For semantic reasons, you can do:
object.class.name #=> 'FooBar'
You can also use tableize with this sequence, for example:
object.class.name.tableize #=> 'foo_bars'
I prefer this because of readability.
Also, note that tableize also performs pluralization. If unwanted use is underscore .
Hope this helps anyone, even if it's an old thread :)
Gabriel Osorio
source share