Away Rails on the road I stumbled upon an interesting post by Err the blog: a nice trip through ActiveSupport, the component of Rails that takes care of extending Ruby's default library.
I'm also posting this here to avoid wasting time every time I look for the right method of 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: uninitialised constant Cheer
>> "Christmas".constantize
=> Christmas
Precedente
18 dicembre 2006
Successivo
20 dicembre 2006
Sono Silvano Stralla. Faccio lo sviluppatore, mi piace fare fotografie e pedalare biciclette.
Se vuoi, puoi scrivermi a silvano.stralla at
sistrall.it.
Questo sito è fatto a mano, con amore, a Torino (Italia).
© 2002—2024 Silvano Stralla
This page was built on Sat, 23 Nov 2024 20:14:05 GMT from code version e8e84b66.