From: James Edward Gray II Date: 2010-10-31T06:53:50+09:00 Subject: Re: Undocumented feature: Array#one? (ruby 1.9.2) On Oct 30, 2010, at 4:45 PM, Siep Korteling wrote: > In (my) ruby 1.9.2 class Array has an undocumented method #one? . It > takes no arguments and returns true if the array contains one element, > false otherwise. Is this something someone forgot to delete? $ ri -T Enumerable#one? Enumerable#one? (from ruby core) ------------------------------------------------------------------------------ enum.one? [{|obj| block }] => true or false ------------------------------------------------------------------------------ Passes each element of the collection to the given block. The method returns true if the block returns true exactly once. If the block is not given, one? will return true only if exactly one of the collection members is true. %w{ant bear cat}.one? {|word| word.length == 4} #=> true %w{ant bear cat}.one? {|word| word.length > 4} #=> false %w{ant bear cat}.one? {|word| word.length < 4} #=> false [ nil, true, 99 ].one? #=> false [ nil, true, false ].one? #=> true James Edward Gray II