Interpret the string source as a body of a block, while passing *args into the block.
A small example explains how the method is supposed to be used and how the *args can be fetched:
class A include DSLKit::Interpreter def c 3 end end A.new.interpret('|a,b| a + b + c', 1, 2) # => 6
To use a specified binding see interpret_with_binding.
# File lib/dslkit/polite.rb, line 206 def interpret(source, *args) interpret_with_binding(source, binding, *args) end
Interpret the string source as a body of a block, while passing *args into the block and using my_binding for evaluation.
A small example:
class A include DSLKit::Interpreter def c 3 end def foo b = 2 interpret_with_binding('|a| a + b + c', binding, 1) # => 6 end end A.new.foo # => 6
See also interpret.
# File lib/dslkit/polite.rb, line 228 def interpret_with_binding(source, my_binding, *args) path = '(interpret)' if source.respond_to? :to_io path = source.path if source.respond_to? :path source = source.to_io.read end block = lambda { |*a| eval("lambda { #{source} }", my_binding, path).call(*a) } instance_exec(*args, &block) end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.