Forked from jdickey/Trivial example of isolating Rails helper logic.rb
Created
February 11, 2015 03:55
-
-
Save Likewise42/31a661481dff3c86ebc4 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| # In app/helpers/users_helper.rb | |
| require_relative 'users_helper/greet' | |
| module UsersHelper | |
| module Internals | |
| end | |
| private_constant :Internals | |
| include Internals | |
| def greet(user) | |
| UserGreeting.new(self).greet(user) | |
| end | |
| # ... | |
| end | |
| # In app/helpers/users_helper.greet.rb | |
| module UsersHelper | |
| module Internals | |
| class UserGreeting | |
| def initialize(helper_module) | |
| @h = helper_module | |
| end | |
| def greet(user) | |
| "Hello, #{user.name}!" | |
| end | |
| end | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment