D
David Madden
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 = self, 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?
Dave.
function is added to the array class:
class Array
def shuffle!
each_index do |i|
j = rand(length-i) + i
self[j], self = self, 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?
Dave.