Skip to content

Instantly share code, notes, and snippets.

@shirts
Created October 10, 2019 21:31
Show Gist options
  • Save shirts/82b81ffa0bafdf07d2301d3fe3ef0f66 to your computer and use it in GitHub Desktop.
Save shirts/82b81ffa0bafdf07d2301d3fe3ef0f66 to your computer and use it in GitHub Desktop.
ERB binding
require 'erb'
class BasicErb
def initialize(template)
@template = template
end
def greeting
"Hello World!"
end
def create!
File.write('index.html', ERB.new(@template).result(binding))
end
end
template = File.read('./index.html.erb')
basic_erb = BasicErb.new(template)
basic_erb.create!
<h1><%= greeting %></h1>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment