Ruby bug in singularizing "leaves"

Discussion in 'Ruby' started by Vineeth Pradhan, Dec 10, 2010.

  1. Hello,

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

    >> "leave".pluralize

    => "leaves"
    >>


    >> "leaves".singularize

    => "leafe"
    >>


    >> "leaf".pluralize

    => "leafs"
    >>


    --
    Posted via http://www.ruby-forum.com/.
     
    Vineeth Pradhan, Dec 10, 2010
    #1
    1. Advertising

  2. On Fri, Dec 10, 2010 at 6:04 AM, Vineeth Pradhan <> wrote:
    > Hello,
    >
    > Has anyone noticed this bug in ruby? in script/console, try
    >
    >>> "leave".pluralize

    > => "leaves"
    >>>

    >
    >>> "leaves".singularize

    > => "leafe"
    >>>

    >
    >>> "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: http://github.com/rubyredrick
    Twitter: @RickDeNatale
    WWR: http://www.workingwithrails.com/person/9021-rick-denatale
    LinkedIn: http://www.linkedin.com/in/rickdenatale
     
    Rick DeNatale, Dec 10, 2010
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jorge_Beteta
    Replies:
    4
    Views:
    8,725
    Shiv Kumar
    Jan 12, 2004
  2. SpamProof

    ghostscript leaves windword processes

    SpamProof, Feb 24, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    375
    SpamProof
    Feb 25, 2004
  3. Bastian
    Replies:
    0
    Views:
    3,682
    Bastian
    Nov 21, 2005
  4. Tim Morgan
    Replies:
    0
    Views:
    117
    Tim Morgan
    Sep 13, 2007
  5. Phlip
    Replies:
    1
    Views:
    99
    Phlip
    Sep 7, 2010
Loading...

Share This Page