Class: Subaltern::Block
- Inherits:
-
Object
- Object
- Subaltern::Block
- Defined in:
- lib/subaltern/evaluator.rb
Overview
Wrapper for Ruby blocks.
Instance Method Summary collapse
- #call(context, arguments, new_context = true) ⇒ Object
-
#initialize(tree) ⇒ Block
constructor
A new instance of Block.
Constructor Details
#initialize(tree) ⇒ Block
Returns a new instance of Block.
240 241 242 243 244 |
# File 'lib/subaltern/evaluator.rb', line 240 def initialize(tree) @arglist = Array(refine(tree[0] || [])).flatten @tree = tree[1] end |
Instance Method Details
#call(context, arguments, new_context = true) ⇒ Object
246 247 248 249 250 251 252 253 254 255 |
# File 'lib/subaltern/evaluator.rb', line 246 def call(context, arguments, new_context=true) arguments = arguments.flatten con = new_context ? Context.new(context, {}) : context @arglist.each_with_index { |a, i| con[a] = arguments[i] } Subaltern.eval_tree(con, @tree) end |