All of these features work with each other.
# Helper method
def render(tmpl, scope = Object.new, locals = {}, &blk)
Tilt['erb'].new { tmpl }.render(scope, locals, &blk)
end
render('<%= self %>', 123) # => 123
Foo = Struct.new(:foo)
render('<%= foo %>, Foo.new(456)) # => 456
# Doesn't work with Proc.new
render('<%= yield %>') { 123 } # => 123
class Scope
FOO = 123
end
# This can't be handled with a simple Proc.new
render('<%= FOO %>', Scope.new) # => 123
Also, when you pass BasicObject as scope, you'll still have access to constants defined on Object:
render('<%= String %>', BasicObject.new) # => "String"