Class: TypedRb::ParsingContext
- Defined in:
- lib/typed/runtime/parser_context.rb
Overview
Helper class used to keep an stack of type signatures being parsed.
Instance Method Summary collapse
- #context_name ⇒ Object
-
#initialize ⇒ ParsingContext
constructor
A new instance of ParsingContext.
- #path_name ⇒ Object
- #pop ⇒ Object
- #push(type) ⇒ Object
- #singleton_class? ⇒ Boolean
- #with_type(type) ⇒ Object
Constructor Details
#initialize ⇒ ParsingContext
Returns a new instance of ParsingContext.
5 6 7 |
# File 'lib/typed/runtime/parser_context.rb', line 5 def initialize @types_stack = [] end |
Instance Method Details
#context_name ⇒ Object
24 25 26 |
# File 'lib/typed/runtime/parser_context.rb', line 24 def context_name @types_stack.last.join('::') end |
#path_name ⇒ Object
28 29 30 |
# File 'lib/typed/runtime/parser_context.rb', line 28 def path_name @types_stack.map { |key| key[1] }.join('::') end |
#pop ⇒ Object
13 14 15 |
# File 'lib/typed/runtime/parser_context.rb', line 13 def pop @types_stack.pop end |
#push(type) ⇒ Object
9 10 11 |
# File 'lib/typed/runtime/parser_context.rb', line 9 def push(type) @types_stack << type end |
#singleton_class? ⇒ Boolean
32 33 34 |
# File 'lib/typed/runtime/parser_context.rb', line 32 def singleton_class? @types_stack.last.first == :self rescue false end |
#with_type(type) ⇒ Object
17 18 19 20 21 22 |
# File 'lib/typed/runtime/parser_context.rb', line 17 def with_type(type) push type result = yield pop result end |