mobile apps singapore,web development singapore,mobile apps development singapore,singapore web development,web design company singapore,developer in singapore,developers in singapore,mobile app development singapore,singapore web design,graphic designer in singapore,web development company singapore,website developer singapore,design firms in singapore,website designer singapore,singapore website design,mobile application developer singapore,web application singapore,web designer singapore,web design singapore,mobile developer singapore,ios app development singapore,android developer singapore,singapore app developer,website design singapore,design agency singapore,singapore mobile application developer,app developer singapore,mobile application development singapore,ruby on rails developer singapore,ios developer singapore,mobile app developer singapore,web design services singapore,website development singapore,app development singapore,mobile game developer singapore,singapore web design services,singapore mobile app developer

Ruby underscore and classify methods

These are two Rails helpers that could be very useful when injecting new instance methods in a class.


Converts from a class name to a underscore attribute.

‘MyClassName’.underscore => my_class_name


Inverse method from underscore.

>> “cool_articles”.classify
=> “CoolArticles”

>> “comment”.classify
=> “Comment”

Both, combined with singularize and pluralize, allows us to handle parent/child methods in a very handy way. For example:

elements_in_ = self.send(parent).send(self.class.to_s.pluralize.underscore)

or things like

Kernel.const_get(table_model.to_s.classify).find(:all) #Kernel.const_get gets an string and retrieves the class.


%d bloggers like this: