Viaggio in ActiveSupport

Via Rails on the road sono capitato su un interessante post di Err the blog: un bel viaggio in ActiveSupport, il componente di Rails che si occupa di estendere la libreria predefinita di Ruby.

Lo riporto qui anche per evitare di perdere ogni volta del tempo quando cerco il metodo giusto di Inflector:

>> "reindeer".pluralize
=> "reindeers" 
>> "elves".singularize
=> "elf" 
>> "christmas_carol".camelize
=> "ChristmasCarol" 
>> "christmas_carol".camelize(:lower)
=> "christmasCarol" 
>> "holiday_cheer".titleize
=> "Holiday Cheer" 
>> "AdventCalendar-2006".underscore
=> "advent_calendar_2006" 
>> "santa_Claus".dasherize
=> "santa-Claus" 
>> "Holiday::December::Christmas".demodulize
=> "Christmas" 
>> "SnowStorm".tableize
=> "snow_storms" 
>> "snow_storms".classify
=> "SnowStorm" 
>> "present_id".humanize
=> "Present" 
>> "Present".foreign_key
=> "present_id" 
>> "Cheer".constantize
NameError: uninitialized constant Cheer
>> "Christmas".constantize
=> Christmas

Post your comment

You can use Textile





0 comments

Readers left 0 notes on this photograph. Live yours using the form below.

Published on
19 December 2006
At
11:48
Tagged
activesupport, inflector, rails, ruby, Article