module Tins::Interpreter

def interpret_with_binding(source, my_binding, *args)

See also #interpret.

A.new.foo # => 6
end
end
interpret_with_binding('|a| a + b + c', binding, 1) # => 6
b = 2
def foo
end
3
def c
include Tins::Interpreter
class A

A small example:

*args into the block and using _my_binding_ for evaluation.
Interpret the string _source_ as a body of a block, while passing
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