Class: Teacher::Function
- Inherits:
-
Object
- Object
- Teacher::Function
- Defined in:
- lib/teacher/function.rb
Instance Method Summary collapse
- #call(scope, args) ⇒ Object
-
#initialize(scope, &block) ⇒ Function
constructor
A new instance of Function.
Constructor Details
#initialize(scope, &block) ⇒ Function
Returns a new instance of Function.
4 5 6 7 |
# File 'lib/teacher/function.rb', line 4 def initialize(scope, &block) @scope = scope @body = block end |
Instance Method Details
#call(scope, args) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/teacher/function.rb', line 9 def call(scope, args) args.reject! { |a| a.text_value.blank? } if args.to_a.any? tmp = [args.first] if args.length > 1 last = args.last.elements.first if last.is_a?(List) tmp += last.eval(self) else tmp << last end end args = tmp end @body.call(*args) end |