-
-
Save apeiros/8889facb6b043175cbb0 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
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