This project is archived and is in readonly mode.
Pluralize doesn't handle uncountable words in a sentence
-
Daniel Schierbeck
- Tag changed from inflector, pluralize, uncountable to inflector, patch, pluralize, uncountable
When you write words = phrase.to_s.dup.split(" "), it seems that dup is redundant, and adds an unnecessary extra memory consumption. split is not destructive, and can safely be called on phrase.to_s.
-
James Adam
Updated patch to avoid using
dup -
James Adam
Great point Daniel
I think the dup was only there as a hold-over from the previous implementation. I'll amend the patch now.
Thanks again,
James
On 14 Nov 2008, at 13:36, Lighthouse wrote:
-
Daniel Schierbeck
+1, with the latest change, this looks like an elegant solution.
-
DHH
Hmm, pluralize(word) intends to me that it's about pluralizing a word, not a phrase. If this was to pass, all the inflectors should be handling phrases. Which I think perhaps is a bit much to promise?
-
James Adam
That could be a fair point; part of the motivation behind the patch is that, by the examples in the RDoc above it, I do expect
pluralizeto work on phrases:"the blue mailman".pluralize # => "the blue mailmen"If that example were to be removed, I wouldn't have so readily expected
pluraliseto work on my phrase ("sports equipment"), and would've created a wrapper for pluralize in my own app.I'm not sure all the inflectors would need to know/care about phrases - probably only pluralize and singularize. As a rough sketch:
def with_last_word(phrase, &block) words = phrase.split(" ") last_word = words.pop words.push(yield(last_word)) words.join(" ") end def pluralize(phrase) with_last_word(phrase) { |w| w + 's' } end def singularize(phrase) with_last_word(phrase) { |w| w.gsub(/s$/, '') } end pluralize("the dancing fool") # => "the dancing fools" singularize("prancing idiots") # => "prancing idiot"If you feel this is worthwhile, I'll work up a proper patch for both methods. Otherwise, I feel that the 'blue mailmen' example should be removed, as it's misleading and encourages the broken behaviour.
-
DHH
- State changed from new to resolved
I agree. I think it's cleaner to keep pluralize/singularize to words as all the other inflectors do that too. I'll remove blue mailmen. Don't know how that snuck in there.
