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

Ruby underscore and classify methods

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

underscore

Converts from a class name to a underscore attribute.

‘MyClassName’.underscore => my_class_name

classify

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.

source: http://yarorb.wordpress.com/2008/05/06/underscore-and-classify/

Malcare WordPress Security