Class: SymbolTable

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/falluto/symboltable.rb

Instance Method Summary collapse

Constructor Details

#initialize(attribute = :name) ⇒ SymbolTable

Returns a new instance of SymbolTable.



4
5
6
7
# File 'lib/falluto/symboltable.rb', line 4

def initialize attribute = :name
  @table = Hash.new
  @attribute = attribute
end

Instance Method Details

#each(&block) ⇒ Object



29
30
31
# File 'lib/falluto/symboltable.rb', line 29

def each &block
  @table.values.each &block
end

#empty?Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/falluto/symboltable.rb', line 25

def empty?
  @table.empty?
end

#get(key) ⇒ Object Also known as: []



20
21
22
# File 'lib/falluto/symboltable.rb', line 20

def get key
  @table[key]
end

#has?(object) ⇒ Boolean

Returns:

  • (Boolean)


9
10
11
12
# File 'lib/falluto/symboltable.rb', line 9

def has? object
  key = object.send(@attribute)
  @table.include? key
end

#insert(object) ⇒ Object Also known as: <<



14
15
16
17
# File 'lib/falluto/symboltable.rb', line 14

def insert(object)
  key = object.send(@attribute)
  @table[key] = object
end