Skip to content

Instantly share code, notes, and snippets.

@apeiros
Created January 4, 2015 00:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save apeiros/8889facb6b043175cbb0 to your computer and use it in GitHub Desktop.
Save apeiros/8889facb6b043175cbb0 to your computer and use it in GitHub Desktop.
require 'erb'
module TemplateVariables
def self.construct(variables)
b = get_binding
variables.each do |key, value|
b.local_variable_set(key, value)
end
b
end
def self.get_binding
binding
end
end
h = {entity: "World", greeting: "Hello"}
b = TemplateVariables.construct(h)
ERB.new("<%= greeting %> <%= entity %>!").result b
# => "Hello World!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment