Class: Crisp::Function

Inherits:
Object
  • Object
show all
Defined in:
lib/crisp/function.rb

Overview

The Crisp function

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#nameObject (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