Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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.
Add Comment
Please, Sign In to add comment