opal/opal-activesupport

String#pluralize does not handle plural

Closed this issue · 3 comments

'objects'.pluralize
  #=> 'objectss`

The issue is with implementation of Active::Inflector#apply_inflections.

Current code is:

          rules.each do |rule, replacement|
            changed = result.sub(rule, replacement)
            unless changed == result
              result = changed
              break
            end
          end

but the rule for a word that is already plural will not change the word, so this test fails.

Suggestion for fix is:

          rules.each do |rule, replacement|
            if result =~ rule
              result = result.sub(rule, replacement)
              break
            end
          end

Need to add appropriate test too.

elia commented

@balmoral thanks for the report, any chance you can send a PR for this?

PR sent. Newbie at PR'ing, so hope done right. Code should be fine, though tests don't cover inflections.

elia commented

PR sent. Newbie at PR'ing, so hope done right. Code should be fine, though tests don't cover inflections.

Sorry for the long delay, I saw the PR and I'll add a couple of comments about some rookie PR'ing mistakes 🙂 (even if the issue has been fixed by #15).