r0man/inflections-clj — pull request #4 by bostonou (2012-09-13 19:32:02+00:00)
Title: Add Inflection test (and fixes) to ensure singularizing a singular actually give you the correct singular in more cases.

This is a fix based on [this rails fix](https://github.com/rails/rails/pull/4719). It ensures singularizing various singular words gives you the correct values.

In order to make this fix, a fix had to be made to the way rules are resolved. In Ruby, [gsub!](http://www.ruby-doc.org/core-1.9.3/String.html#method-i-gsub-21) returns `nil` if no substitution is made. In Clojure, [replace](http://clojure.github.com/clojure/clojure.string-api.html#clojure.string/replace) will return the original string if no substitution is made.

This means that we can't simply compare the original and result word and make a decision based on whether or not they are the same. We first have to see if the regular expression matches. If it matches, then we can perform the replacement and return the word without considering if the word has changed.

Consider:

````ruby
"status".gsub!(/(status)(es)?$/i, '\1') # => "status"
"status".gsub!(/non-matching/, '\1') # => nil
````

````clojure
(replace "status" #"(?i)(status)(es)?$" "$1") ; => "status"
(replace "status" #"non-matching" "$1") ; => "status"
````