Hello,
Has anyone noticed this bug in ruby? in script/console, try
“leave”.pluralize
=> “leaves”
“leaves”.singularize
=> “leafe”
“leaf”.pluralize
=> “leafs”
Hello,
Has anyone noticed this bug in ruby? in script/console, try
“leave”.pluralize
=> “leaves”
“leaves”.singularize
=> “leafe”
“leaf”.pluralize
=> “leafs”
On Fri, Dec 10, 2010 at 6:04 AM, Vineeth P. [email protected]
wrote:
“leaf”.pluralize
=> “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”
HTH
–
Rick DeNatale
Blog: http://talklikeaduck.denhaven2.com/
Github: rubyredrick (Rick DeNatale) · GitHub
Twitter: @RickDeNatale
WWR: http://www.workingwithrails.com/person/9021-rick-denatale
LinkedIn: http://www.linkedin.com/in/rickdenatale
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.
Sponsor our Newsletter | Privacy Policy | Terms of Service | Remote Ruby Jobs