Skip to content

Instantly share code, notes, and snippets.

@awwaiid
Created December 7, 2016 04:09
Show Gist options
  • Save awwaiid/30d05378f6a95dca72fcba5e983af5e7 to your computer and use it in GitHub Desktop.
Save awwaiid/30d05378f6a95dca72fcba5e983af5e7 to your computer and use it in GitHub Desktop.
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