Class: Flea::Environment

Inherits:
Object
  • Object
show all
Defined in:
lib/flea/environment.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#parentObject

Returns the value of attribute parent.



5
6
7
# File 'lib/flea/environment.rb', line 5

def parent
  @parent
end

#tableObject

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

Returns:

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