My Profile Photo

rubycoloredglasses


I'm Jason, a web applications developer in the San Francisco Bay area.


Ruby Class Name

I noticed that in a module used on the CalCentral project that logger expressions used in a module referenced ‘self.name’ many times. I checked ApiDock.com for a reference to this class in the Ruby or Rails documentation, but I couldn’t find one. The module itself didn’t define a #name method, so I was perplexed.

The module I was inspecting is meant to be used to extend other classes, meaning that it establishes the methods as class methods. It turns out that the ‘Class’ class is officially documented as having a #name method that returns a string version of the class name. This is a valid way of logging which class the log message originates from.