Skip to content

Instantly share code, notes, and snippets.

@tjhanley
Created August 6, 2013 20:50
Show Gist options
  • Save tjhanley/6168509 to your computer and use it in GitHub Desktop.
Save tjhanley/6168509 to your computer and use it in GitHub Desktop.
Need a better way....
def perform(user_id, class_name)
user = eval class_name + '.find(' + user_id.to_s + ')'
end
@tjhanley
Copy link
Author

tjhanley commented Aug 6, 2013

eval makes me feel oogy

@danielevans
Copy link

So twitter just crapped out on me.

How about:

    user = class_name.constantize.public_send(:find, user_id)

@danielevans
Copy link

I suppose you don't actually need the public send, either.

  class_name.constantize.find(user_id)

@alvinlai
Copy link

alvinlai commented Aug 6, 2013

+1 on constantize

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment