From: Tamreen Khan Date: 2007-01-17T04:15:23+09:00 Subject: Re: what is dup? ------=_Part_60690_819910.1168974921618 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline On 1/16/07, Wilson Bilkovich wrote: > > On 1/16/07, David Madden wrote: > > I am playing with an example in the ruby cookbook where a shuffle > > function is added to the array class: > > > > class Array > > > > def shuffle! > > each_index do |i| > > j = rand(length-i) + i > > self[j], self[i] = self[i], self[j] > > end > > end > > > > def shuffle > > dup.shuffle! > > end > > > > end > > > > What I don't understand is the line "dup.shuffle!" > > > > What is the dup object? > > > I think a wordier but equivalent way of doing that is: > return self.dup.shuffle! That just means "duplicate myself, shuffle the duplicate, then return it." ------=_Part_60690_819910.1168974921618--