Skip to content

Instantly share code, notes, and snippets.

@matschaffer
Created December 11, 2008 20:22
Show Gist options
  • Select an option

  • Save matschaffer/34861 to your computer and use it in GitHub Desktop.

Select an option

Save matschaffer/34861 to your computer and use it in GitHub Desktop.
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