Class: Verneuil::SymbolTable
- Inherits:
-
Object
- Object
- Verneuil::SymbolTable
- Defined in:
- lib/verneuil/symbol_table.rb
Overview
A registry for methods.
Instance Attribute Summary collapse
-
#methods ⇒ Object
readonly
Returns the value of attribute methods.
Instance Method Summary collapse
-
#add(method) ⇒ Object
Defines a function.
-
#initialize ⇒ SymbolTable
constructor
A new instance of SymbolTable.
-
#lookup_method(recv, name) ⇒ Object
Returns the function that matches the given receiver and method name.
Constructor Details
#initialize ⇒ SymbolTable
Returns a new instance of SymbolTable.
7 8 9 |
# File 'lib/verneuil/symbol_table.rb', line 7 def initialize @methods = {} end |
Instance Attribute Details
#methods ⇒ Object (readonly)
Returns the value of attribute methods.
5 6 7 |
# File 'lib/verneuil/symbol_table.rb', line 5 def methods @methods end |
Instance Method Details
#add(method) ⇒ Object
Defines a function. This function will override the default of calling back to Ruby. Methods added here must support at least #receiver, #name and #invoke.
Example:
# Replaces Foo#bar with the V method at address 15.
add(method_obj)
19 20 21 22 |
# File 'lib/verneuil/symbol_table.rb', line 19 def add(method) key = [method.receiver, method.name] @methods[key] = method end |
#lookup_method(recv, name) ⇒ Object
Returns the function that matches the given receiver and method name.
26 27 28 29 30 31 32 33 34 |
# File 'lib/verneuil/symbol_table.rb', line 26 def lookup_method(recv, name) key = if recv [recv.class.name.to_sym, name] else [nil, name] end @methods[key] end |