Skip to content

Instantly share code, notes, and snippets.

@jamesmoriarty
Created March 16, 2012 08:54
Show Gist options
  • Save jamesmoriarty/2049208 to your computer and use it in GitHub Desktop.
Save jamesmoriarty/2049208 to your computer and use it in GitHub Desktop.
render erb template
1.9.2p290 :013 > render_erb("Hey, <%= first_name %> <%= last_name %>", :first_name => "James", :last_name => "Moriarty")
=> "Hey, James Moriarty"
require 'erb'
require 'ostruct'
def render_erb(template, locals)
ERB.new(template).result(OpenStruct.new(locals).instance_eval{ binding })
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment