Class: TypedRb::ParsingContext

Inherits:
Object
  • Object
show all
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

Constructor Details

#initializeParsingContext

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_nameObject



24
25
26
# File 'lib/typed/runtime/parser_context.rb', line 24

def context_name
  @types_stack.last.join('::')
end

#path_nameObject



28
29
30
# File 'lib/typed/runtime/parser_context.rb', line 28

def path_name
  @types_stack.map { |key| key[1] }.join('::')
end

#popObject



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

Returns:

  • (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