Created
December 7, 2016 04:09
-
-
Save awwaiid/30d05378f6a95dca72fcba5e983af5e7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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