J
Jeff Moore
This works but I can't escape the nagging sense that there's a more
concise approach (for one thing, it looks like there are way too
transient objects to me).
Anyone have a better idea?
class Array
def shuffle
t_self = self.dup
t_size = self.size
result=[]
t_size.times { result << t_self.slice!(rand(t_self.size)) }
result
end
def shuffle!
t_self = self.dup
t_size = self.size
self.clear
t_size.times { self << t_self.slice!(rand(t_self.size)) }
self
end
end
Regards...
concise approach (for one thing, it looks like there are way too
transient objects to me).
Anyone have a better idea?
class Array
def shuffle
t_self = self.dup
t_size = self.size
result=[]
t_size.times { result << t_self.slice!(rand(t_self.size)) }
result
end
def shuffle!
t_self = self.dup
t_size = self.size
self.clear
t_size.times { self << t_self.slice!(rand(t_self.size)) }
self
end
end
Regards...