Class: StackState
- Inherits:
-
Object
- Object
- StackState
- Defined in:
- lib/ruby_parser_extras.rb
Instance Attribute Summary collapse
-
#stack ⇒ Object
readonly
Returns the value of attribute stack.
Instance Method Summary collapse
-
#initialize(name) ⇒ StackState
constructor
A new instance of StackState.
- #inspect ⇒ Object
- #is_in_state ⇒ Object
- #lexpop ⇒ Object
- #pop ⇒ Object
- #push(val) ⇒ Object
Constructor Details
#initialize(name) ⇒ StackState
Returns a new instance of StackState.
657 658 659 660 |
# File 'lib/ruby_parser_extras.rb', line 657 def initialize(name) @name = name @stack = [false] end |
Instance Attribute Details
#stack ⇒ Object (readonly)
Returns the value of attribute stack.
655 656 657 |
# File 'lib/ruby_parser_extras.rb', line 655 def stack @stack end |
Instance Method Details
#inspect ⇒ Object
662 663 664 |
# File 'lib/ruby_parser_extras.rb', line 662 def inspect "StackState(#{@name}, #{@stack.inspect})" end |
#is_in_state ⇒ Object
666 667 668 |
# File 'lib/ruby_parser_extras.rb', line 666 def is_in_state @stack.last end |
#lexpop ⇒ Object
670 671 672 673 674 675 |
# File 'lib/ruby_parser_extras.rb', line 670 def lexpop raise if @stack.size == 0 a = @stack.pop b = @stack.pop @stack.push(a || b) end |
#pop ⇒ Object
677 678 679 680 681 |
# File 'lib/ruby_parser_extras.rb', line 677 def pop r = @stack.pop @stack.push false if @stack.size == 0 r end |
#push(val) ⇒ Object
683 684 685 686 |
# File 'lib/ruby_parser_extras.rb', line 683 def push val raise if val != true and val != false @stack.push val end |