Class: Flea::Environment
- Inherits:
-
Object
- Object
- Flea::Environment
- Defined in:
- lib/flea/environment.rb
Instance Attribute Summary collapse
-
#parent ⇒ Object
Returns the value of attribute parent.
-
#table ⇒ Object
Returns the value of attribute table.
Instance Method Summary collapse
- #define(name, value) ⇒ Object
- #find(name) ⇒ Object
- #has_variable?(name) ⇒ Boolean
-
#initialize(parent = nil) ⇒ Environment
constructor
A new instance of Environment.
Constructor Details
#initialize(parent = nil) ⇒ Environment
Returns a new instance of Environment.
7 8 9 10 11 |
# File 'lib/flea/environment.rb', line 7 def initialize(parent = nil) @parent = parent @table = {} add_globals if @parent.nil? end |
Instance Attribute Details
#parent ⇒ Object
Returns the value of attribute parent.
5 6 7 |
# File 'lib/flea/environment.rb', line 5 def parent @parent end |
#table ⇒ Object
Returns the value of attribute table.
5 6 7 |
# File 'lib/flea/environment.rb', line 5 def table @table end |
Instance Method Details
#define(name, value) ⇒ Object
27 28 29 |
# File 'lib/flea/environment.rb', line 27 def define(name, value) @table[name] = value end |
#find(name) ⇒ Object
20 21 22 23 24 25 |
# File 'lib/flea/environment.rb', line 20 def find(name) return @table[name] if @table.key?(name) return nil if @parent.nil? @parent.find(name) end |
#has_variable?(name) ⇒ Boolean
13 14 15 16 17 18 |
# File 'lib/flea/environment.rb', line 13 def has_variable?(name) return true if @table.key?(name) return false if @parent.nil? @parent.has_variable?(name) end |