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

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/

%d bloggers like this:
WordPress