Created
December 11, 2015 19:44
-
-
Save smedstadc/67005e648c329c52499f to your computer and use it in GitHub Desktop.
Basic Ruby Decorator
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 Decorator | |
# Uncomment for Rails | |
# | |
# include ActionView::Helpers::UrlHelper | |
attr_reader :decorated | |
def initialize(decorated) | |
@decorated = decorated | |
init_hook | |
end | |
private | |
# Uncomment for Rails | |
# | |
# def helpers | |
# Rails.application.routes.url_helpers | |
# end | |
def init_hook | |
raise "You forgot to implement the init_hook. Hope this helps." | |
end | |
def method_missing(m, *args, &block) | |
@decorated.send(m, *args, &block) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment