How can I programmatically turn a class name, FooBar, into a symbol, :foo_bar? e.g. something like this, but that handles camel case properly?
FooBar.to_s.downcase.to_sym
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Rails comes with a method called
underscorethat will allow you to transform CamelCased strings into underscore_separated strings. So you might be able to do this:But you will have to install ActiveSupport just to do that, as ipsum says.
If you don’t want to install ActiveSupport just for that, you can monkey-patch
underscoreintoStringyourself (the underscore function is defined in ActiveSupport::Inflector):