Created
December 11, 2008 20:22
-
-
Save matschaffer/34861 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
| class AClassThatUsesSend | |
| def action | |
| # here's where the action happens | |
| @helper_type = "foo" | |
| # this is equivalent to self.foo_helper or just foo_helper | |
| send("#{@helper_type}_helper") | |
| end | |
| def foo_helper | |
| #more fun here | |
| end | |
| end | |
| # of course you don't want to just take user input unfiltered and feed it | |
| # into send() for possible safety concerns, so consider something like this if | |
| # @helper_type comes from a param | |
| valid_helpers = ['foo', 'bar', 'quux'] | |
| send("#{@helper_type}_helper"} if valid_helpers.include? @helper_type | |
| # There are many ways you could sanitize the value of @helper_type. | |
| # This is just one approach. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment