Rails comes with a method called underscore that will allow you to transform CamelCased strings into underscore_separated strings. So you might be able to do this:
FooBar.name.underscore.to_sym
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 underscore into String yourself (the underscore function is defined in ActiveSupport::Inflector):
class String
def underscore
word = self.dup
word.gsub!(/::/, '/')
word.gsub!(/([A-Z]+)([A-Z][a-z])/,'\1_\2')
word.gsub!(/([a-z\d])([A-Z])/,'\1_\2')
word.tr!("-", "_")
word.downcase!
word
end
end
module MyModule
module ClassMethods
def class_to_sym
name_without_namespace = name.split("::").last
name_without_namespace.gsub(/([^\^])([A-Z])/,'\1_\2').downcase.to_sym
end
end
def self.included(base)
base.extend(ClassMethods)
end
end
class ThisIsMyClass
include MyModule
end
ThisIsMyClass.class_to_sym #:this_is_my_class