Class: Nydp::LexicalContext
- Inherits:
-
Object
- Object
- Nydp::LexicalContext
- Defined in:
- lib/nydp/lexical_context.rb
Instance Attribute Summary collapse
-
#parent ⇒ Object
readonly
Returns the value of attribute parent.
-
#values ⇒ Object
readonly
Returns the value of attribute values.
Instance Method Summary collapse
- #at(name) ⇒ Object
-
#initialize(parent) ⇒ LexicalContext
constructor
A new instance of LexicalContext.
- #nth(n) ⇒ Object
- #set(name, value) ⇒ Object
- #to_s ⇒ Object
- #to_s_with_indent(str) ⇒ Object
Constructor Details
#initialize(parent) ⇒ LexicalContext
Returns a new instance of LexicalContext.
4 5 6 7 |
# File 'lib/nydp/lexical_context.rb', line 4 def initialize parent @parent = parent @values = { } end |
Instance Attribute Details
#parent ⇒ Object (readonly)
Returns the value of attribute parent.
2 3 4 |
# File 'lib/nydp/lexical_context.rb', line 2 def parent @parent end |
#values ⇒ Object (readonly)
Returns the value of attribute values.
2 3 4 |
# File 'lib/nydp/lexical_context.rb', line 2 def values @values end |
Instance Method Details
#at(name) ⇒ Object
20 21 22 |
# File 'lib/nydp/lexical_context.rb', line 20 def at name values[name] end |
#nth(n) ⇒ Object
9 10 11 12 13 14 15 16 17 18 |
# File 'lib/nydp/lexical_context.rb', line 9 def nth n case n when 0 self when -1 raise "wrong nesting level" else parent.nth(n - 1) end end |
#set(name, value) ⇒ Object
24 25 26 |
# File 'lib/nydp/lexical_context.rb', line 24 def set name, value values[name] = value end |
#to_s ⇒ Object
35 36 37 |
# File 'lib/nydp/lexical_context.rb', line 35 def to_s to_s_with_indent '' end |
#to_s_with_indent(str) ⇒ Object
28 29 30 31 32 33 |
# File 'lib/nydp/lexical_context.rb', line 28 def to_s_with_indent str me = @values.map { |k, v| [str, k, "=>", v].join ' ' }.join "\n" me + (parent ? parent.to_s_with_indent(" #{str}") : '') end |