Skip to content

Instantly share code, notes, and snippets.

@epitron
Created December 4, 2014 04:59
Show Gist options
  • Save epitron/0701603bbe76a0f3acd5 to your computer and use it in GitHub Desktop.
Save epitron/0701603bbe76a0f3acd5 to your computer and use it in GitHub Desktop.
Crazy Ruby Templating System, using Regular Ruby Strings!
require 'binding_of_caller'
class Tmpl
def initialize(&block)
@tmpl = block
end
def render
@thebinding = binding.of_caller(1)
instance_eval &@tmpl
end
def method_missing(name, *args)
@thebinding.eval("#{name}")
end
end
t = Tmpl.new do
%{ #{var} is my favorite! }
end
var = 5
p t.render
var = 10
p t.render
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment