Class: Campa::Lambda
- Inherits:
-
Object
- Object
- Campa::Lambda
- Defined in:
- lib/campa/lambda.rb
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
Returns the value of attribute body.
-
#closure ⇒ Object
readonly
Returns the value of attribute closure.
-
#params ⇒ Object
readonly
Returns the value of attribute params.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #call(*args, env:) ⇒ Object
-
#initialize(params, body, closure = Context.new) ⇒ Lambda
constructor
A new instance of Lambda.
Constructor Details
Instance Attribute Details
#body ⇒ Object (readonly)
Returns the value of attribute body.
3 4 5 |
# File 'lib/campa/lambda.rb', line 3 def body @body end |
#closure ⇒ Object (readonly)
Returns the value of attribute closure.
3 4 5 |
# File 'lib/campa/lambda.rb', line 3 def closure @closure end |
#params ⇒ Object (readonly)
Returns the value of attribute params.
3 4 5 |
# File 'lib/campa/lambda.rb', line 3 def params @params end |
Instance Method Details
#==(other) ⇒ Object
23 24 25 26 27 |
# File 'lib/campa/lambda.rb', line 23 def ==(other) return false if !other.is_a?(Campa::Lambda) params == other.params && body == other.body end |
#call(*args, env:) ⇒ Object
12 13 14 15 16 17 18 19 20 21 |
# File 'lib/campa/lambda.rb', line 12 def call(*args, env:) raise arity_error(args) if params.to_a.length != args.length @body.reduce(nil) do |_, expression| evaler.call( expression, invocation_env(env, args) ) end end |