Dde3b34749219173bbf3e07ca710eccc

What is the best way to simplify a list of method calls on regular expressions?
See http://github.com/rails/rails/blob/37be453a8709eb30c97f26369e352e5935436d97/activesupport/lib/active_support/inflections.rb for more context.

1
2
3
4
5
6
7
8
9
10
11
12
module ActiveSupport
  Inflector.inflections do |inflect|
    inflect.plural(/$/, 's')
    inflect.plural(/s$/i, 's')
    inflect.plural(/(ax|test)is$/i, '\1es')
    inflect.plural(/(octop|vir)us$/i, '\1i')
    inflect.plural(/(alias|status)$/i, '\1es')
    inflect.plural(/(bu)s$/i, '\1ses')
    inflect.plural(/(buffal|tomat)o$/i, '\1oes')
    ...
  end
end

Refactorings

No refactoring yet !

880cbab435f00197613c9cc2065b4f5a

danielharan

June 11, 2009, June 11, 2009 13:40, permalink

No rating. Login to rate!

You could iterate over them in the regular way. While it's a bit verbose it's also very straight-forward to read and there's not much to gain from making it shorter, so I'd leave this as is.

Dde3b34749219173bbf3e07ca710eccc

reprogrammer.myopenid.com

June 11, 2009, June 11, 2009 16:40, permalink

No rating. Login to rate!

Do you say that it doesn't deserve a refactoring because there are only 7 method calls in my code snippet?
Does looking at the whole method by following the provided github link change your mind?

Your refactoring





Format Copy from initial code

or Cancel