Class: Environment
Instance Attribute Summary collapse
-
#defaults ⇒ Object
readonly
Returns the value of attribute defaults.
-
#parent ⇒ Object
readonly
Returns the value of attribute parent.
Instance Method Summary collapse
- #define(symbol, value) ⇒ Object
- #defined?(symbol) ⇒ Boolean
-
#initialize(parent = nil, defaults = {}) ⇒ Environment
constructor
A new instance of Environment.
- #lookup(symbol) ⇒ Object
- #set(symbol, value) ⇒ Object
Constructor Details
#initialize(parent = nil, defaults = {}) ⇒ Environment
Returns a new instance of Environment.
4 5 6 7 |
# File 'lib/forsta/environment.rb', line 4 def initialize(parent=nil, defaults={}) @parent = parent @defaults = defaults end |
Instance Attribute Details
#defaults ⇒ Object (readonly)
Returns the value of attribute defaults.
2 3 4 |
# File 'lib/forsta/environment.rb', line 2 def defaults @defaults end |
#parent ⇒ Object (readonly)
Returns the value of attribute parent.
2 3 4 |
# File 'lib/forsta/environment.rb', line 2 def parent @parent end |
Instance Method Details
#define(symbol, value) ⇒ Object
9 10 11 |
# File 'lib/forsta/environment.rb', line 9 def define(symbol, value) defaults[symbol] = value end |
#defined?(symbol) ⇒ Boolean
13 14 15 |
# File 'lib/forsta/environment.rb', line 13 def defined?(symbol) defaults.has_key?(symbol) || (parent && parent.defined?(symbol)) end |
#lookup(symbol) ⇒ Object
17 18 19 20 |
# File 'lib/forsta/environment.rb', line 17 def lookup(symbol) defaults[symbol] || (parent && parent.lookup(symbol)) || raise("#{symbol} is undefined") end |
#set(symbol, value) ⇒ Object
22 23 24 25 26 27 28 29 30 |
# File 'lib/forsta/environment.rb', line 22 def set(symbol, value) if defaults.has_key?(symbol) defaults[symbol] = value elsif parent.nil? raise("#{symbol} was undefined") else parent.set(symbol, value) end end |