Module: Rexpl::GeneratorMethods

Defined in:
lib/rexpl/generator_methods.rb

Overview

Extends the Rubinius::Generator class with some utility methods used by Replx.

Instance Method Summary collapse

Instance Method Details

Prints the topmost element on the stack and the stack’s current size.

Calling this method neither consumes nor produces stack, it’s just used for debugging the current state.



10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/rexpl/generator_methods.rb', line 10

def print_debug_info
  initial_size = size
  dup
  push_const :Rexpl
  find_const :Output
  swap_stack
  send :inspect, 0, true
  push_literal initial_size
  swap_stack
  send :print_debug_info, 2, true 
  pop
end

#return_stackObject

Returns an array with all the elements currently in the stack.

Calling #return_stack increases by 1 the stack size (being the topmost element an array containing a duplicate of every other element in the stack).



28
29
30
31
32
# File 'lib/rexpl/generator_methods.rb', line 28

def return_stack
  initial_size = size
  dup_many initial_size
  make_array initial_size
end

#sizeFixnum

Returns the current size of the stack.

Returns:

  • (Fixnum)

    the current size of the stack.



37
38
39
# File 'lib/rexpl/generator_methods.rb', line 37

def size
  @current_block.instance_eval { @stack }
end