Ruby bug in singularizing "leaves"


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

=> “leaves”

=> “leafe”

=> “leafs”

On Fri, Dec 10, 2010 at 6:04 AM, Vineeth P. [email protected]

=> “leafs”

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”


Rick DeNatale

Github: rubyredrick (Rick DeNatale) · GitHub
Twitter: @RickDeNatale