Class: Theta::Environment

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

Overview

particular level

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(parent = nil) ⇒ Environment



8
9
10
11
12
13
14
15
# File 'lib/theta/environment.rb', line 8

def initialize(parent = nil)
  @parent = parent
  @table = {}
  if @parent.nil?
    define("#t".to_sym, true)
    define("#f".to_sym, false)
  end
end

Instance Attribute Details

#parentObject

Returns the value of attribute parent.



6
7
8
# File 'lib/theta/environment.rb', line 6

def parent
  @parent
end

Instance Method Details

#define(name, value) ⇒ Object

define an item in the environment



29
30
31
# File 'lib/theta/environment.rb', line 29

def define(name, value)
  @table[name] = value
end

#find(name) ⇒ Object

find an item in the environment



18
19
20
21
22
23
24
25
26
# File 'lib/theta/environment.rb', line 18

def find(name)
  if @table.has_key?(name)
    return @table[name]
  elsif @parent.nil?
    return nil
  else
    @parent.find(name)
  end
end