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.
969 970 971 972 |
# File 'lib/ruby_parser_extras.rb', line 969 def initialize(name) @name = name @stack = [false] end |
Instance Attribute Details
#stack ⇒ Object (readonly)
Returns the value of attribute stack.
967 968 969 |
# File 'lib/ruby_parser_extras.rb', line 967 def stack @stack end |
Instance Method Details
#inspect ⇒ Object
974 975 976 |
# File 'lib/ruby_parser_extras.rb', line 974 def inspect "StackState(#{@name}, #{@stack.inspect})" end |
#is_in_state ⇒ Object
978 979 980 |
# File 'lib/ruby_parser_extras.rb', line 978 def is_in_state @stack.last end |
#lexpop ⇒ Object
982 983 984 985 986 987 |
# File 'lib/ruby_parser_extras.rb', line 982 def lexpop raise if @stack.size == 0 a = @stack.pop b = @stack.pop @stack.push(a || b) end |
#pop ⇒ Object
989 990 991 992 993 |
# File 'lib/ruby_parser_extras.rb', line 989 def pop r = @stack.pop @stack.push false if @stack.size == 0 r end |
#push(val) ⇒ Object
995 996 997 |
# File 'lib/ruby_parser_extras.rb', line 995 def push val @stack.push val end |