Class: Dentaku::AST::FunctionRegistry
- Inherits:
-
Hash
- Object
- Hash
- Dentaku::AST::FunctionRegistry
- Defined in:
- lib/dentaku/ast/function_registry.rb
Class Method Summary collapse
Instance Method Summary collapse
- #default ⇒ Object
- #get(name) ⇒ Object
- #register(name, type, implementation) ⇒ Object
- #register_class(name, function_class) ⇒ Object
Class Method Details
Instance Method Details
#default ⇒ Object
49 50 51 |
# File 'lib/dentaku/ast/function_registry.rb', line 49 def default self.class.default end |
#get(name) ⇒ Object
4 5 6 7 8 9 |
# File 'lib/dentaku/ast/function_registry.rb', line 4 def get(name) name = function_name(name) return self[name] if has_key?(name) return default[name] if default.has_key?(name) fail ParseError, "Undefined function #{ name }" end |
#register(name, type, implementation) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/dentaku/ast/function_registry.rb', line 11 def register(name, type, implementation) function = Class.new(Function) do def self.implementation=(impl) @implementation = impl end def self.implementation @implementation end def self.type=(type) @type = type end def self.type @type end def value(context={}) args = @args.map { |a| a.value(context) } self.class.implementation.call(*args) end def type self.class.type end end function.implementation = implementation function.type = type self[function_name(name)] = function end |
#register_class(name, function_class) ⇒ Object
45 46 47 |
# File 'lib/dentaku/ast/function_registry.rb', line 45 def register_class(name, function_class) self[function_name(name)] = function_class end |