Ruby bug in singularizing "leaves"

R

Rick DeNatale

Hello,

Has anyone noticed this bug in ruby? in script/console, try

First, String#singularize and String#pluralize aren't part of the
Ruby language, they are extensions made by the activesupport gem which
is part of Rails.
Rails uses them pretty extensively to implement "convention over
configuration" things like having a PeopleController to manage a
collection of Person resources.

Second, although activesupport covers a good part of the English
language, there are some gaps, apparently you've found one of these.

Third, the Rails core team won't fix these gaps because they might
break existing Rails apps.

Finally, active support allows YOU to change how these methods work
for such exceptions for YOUR application. For example:


ruby-1.8.7-p302 > "leaf".pluralize
=> "leafs"
ruby-1.8.7-p302 > "leaves".singularize
=> "leafe"
ruby-1.8.7-p302 > ActiveSupport::Inflector.inflections do |inflect|
ruby-1.8.7-p302 > inflect.irregular "leaf", "leaves"
ruby-1.8.7-p302 ?> end
=>

ruby-1.8.7-p302 > "leaf".pluralize
=> "leaves"
ruby-1.8.7-p302 > "leaves".singularize
=> "leaf"

HTH


--
Rick DeNatale

Blog: http://talklikeaduck.denhaven2.com/
Github: http://github.com/rubyredrick
Twitter: @RickDeNatale
WWR: http://www.workingwithrails.com/person/9021-rick-denatale
LinkedIn: http://www.linkedin.com/in/rickdenatale
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top