Skip to content

Instantly share code, notes, and snippets.

@sonota88
Created February 8, 2016 11:45
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 sonota88/4317a521d02cf594c341 to your computer and use it in GitHub Desktop.
Save sonota88/4317a521d02cf594c341 to your computer and use it in GitHub Desktop.
erb context
class ErbContext
def initialize params
@params = params
end
def method_missing name, *args
if @params.has_key? name
@params[name]
else
raise "unknown key (#{name})"
end
end
def get_binding
binding
end
def self.hash_to_binding params
ErbContext.new(params).get_binding
end
end
def render template, params
erb = ERB.new(template)
erb.result ErbContext.hash_to_binding(params)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment