Class: Crisp::Function
- Inherits:
-
Object
- Object
- Crisp::Function
- Defined in:
- lib/crisp/function.rb
Overview
The Crisp function
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
-
#bind(name, env) ⇒ Object
bind the function to the given name in the given environment.
-
#eval(env, args = []) ⇒ Object
evaluate the function by using the given environment and argument list.
-
#initialize(&blk) ⇒ Function
constructor
create new function by calling new with a code block.
Constructor Details
#initialize(&blk) ⇒ Function
create new function by calling new with a code block
7 8 9 10 |
# File 'lib/crisp/function.rb', line 7 def initialize(&blk) @name = nil @blk = blk end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
4 5 6 |
# File 'lib/crisp/function.rb', line 4 def name @name end |
Instance Method Details
#bind(name, env) ⇒ Object
bind the function to the given name in the given environment
13 14 15 16 |
# File 'lib/crisp/function.rb', line 13 def bind(name, env) @name = name.to_sym env[name] = self end |
#eval(env, args = []) ⇒ Object
evaluate the function by using the given environment and argument list
19 20 21 |
# File 'lib/crisp/function.rb', line 19 def eval(env, args = []) FunctionRunner.run(@blk, env, args, name) end |