Created
January 12, 2014 15:36
-
-
Save garethrees/8386142 to your computer and use it in GitHub Desktop.
Create a template rendering class with ERB | http://garethrees.co.uk/2014/01/12/create-a-template-rendering-class-with-erb/
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
class WelcomeMessage < ERB | |
def self.template | |
"Welcome, <%= @name %>" | |
end | |
def initialize(name, options = {}) | |
@name = name | |
@template = options.fetch(:template, self.class.template) | |
super(@template) | |
end | |
def result | |
super(binding) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment