require 'erb'
def foo(template, &block)
o = Object.new
o.instance_eval(&block)
result = ERB.new(template).result(o.instance_eval {binding} )
end
template = "Foo: <%= @foo %>"
expanded_template = foo(template) do
@foo = 1
end
puts expanded_template # => Foo: 1