From: Gavin Sinclair Date: 2004-11-30T10:32:24+09:00 Subject: Re: Seeking advice on some method names On Tuesday, November 30, 2004, 1:52:49 AM, itsme213 wrote: >> But I don't think Enumerable#one? and Array#one are complementary; >> they seem entirely different. > Array#one {|x| pred} would complement Enumerable#one? {|x| pred} > so > Array#one > is same as Array#one{|x|true} > which complements Enumerable#one?{|x|true} >> Likewise with Array#any: it's useful, but really has nothing to do >> with #any? > Array#any{|x| pred} complements Enumerable#any? {|x| pred} > so > Array#any complements Enumerable#any?{|x|true} Two equivalent code samples: A) numbers.one { |n| n.prime? } numbers.any { |n| n.prime? } B) numbers.select { |n| n.prime? }.only numbers.select { |n| n.prime? }.rand I find (B) more intuitive. I'd rather see #select doing the selection, instead of introducing yet more methods that select elements. [1] Further, #rand and #only are telling me what they're doing. #one and #any are "merely" complements of #one? and #any?. To expand further, I find #any quite reasonable, but #rand more so. Array#rand is something I've implemented occasionally, and have seen other requests and references. I find #one quite uncompelling, because it sounds like #any: it doesn't express its one_and_only_one meaning. Cheers, Gavin [1] There are valid reasons to introduce more selection methods, but these don't qualify, to my mind.