From: Dave Aronson Date: 2013-01-13T05:14:48+09:00 Subject: Re: uniq vs uniq! On Sat, Jan 12, 2013 at 3:03 PM, rubyinfo wrote: > 1.8.7 :001 > [].uniq! > => nil > 1.8.7 :002 > [].uniq > => [] > > 1.9.3p194 :001 > [].uniq > => [] > 1.9.3p194 :002 > [].uniq! > => nil > > > Why ? Why what? Why are the results reversed? They're not, you typed them in one order the first time and the other the second. Why does the bang version return nil? As the docs (http://www.ruby-doc.org/core-1.9.3/Array.html#method-i-uniq-21) say, "Returns nil if no changes are made (that is, no duplicates are found)." Of course in [] there will be no dups. Why IS there a difference? Generally, when there are both bang and normal versions of a method, the bang version affects the object passed in, while the normal version acts on (and returns) a duplicate. In the bang case, you usually don't care about the return value, and are using it instead for the effect on the receiver. Why do fools fall in love? Why do birds sing? Why is this night different from all other nights? Why ask why, drink Bud Dry! ;-) -Dave -- Dave Aronson, the T. Rex of Codosaurus LLC, secret-cleared freelance software developer taking contracts in or near NoVa or remote. See information at http://www.Codosaur.us/.