Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
class Template
def initialize(&block)
@body = block
end
def method_missing(v)
@params[v]
end
def render(params)
@params = params
instance_eval &@body
end
end
t = Template.new do
"My name is #{name} and I am #{age}"
end
puts t.render(name: "alice", age: 27)
puts t.render(name: "bob", age: 6)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.