From: Gregory Brown Date: 2008-08-08T12:01:30+09:00 Subject: [ruby-core:18187] Re: New array methods cycle, choice, shuffle (plus bug in cycle) On Thu, Aug 7, 2008 at 10:54 PM, Charles Oliver Nutter wrote: > Florian Frank wrote: >> Because nobody has mentioned this yet: I know, that rails defines a method >> with that name in Array, but I think it is a bad idea. It breaks existing >> and future code, that expects Array#rand to be Kernel#rand and have the same >> signature and semantics of it, while being in context of an Array instance. >> It makes it much more difficult to get any random number out of ruby in this >> context, even if you are aware of Array#rand. > > Kernel#rand is not callable as a method: > > ruby -e "[1,2,3].rand" > -e:1: private method `rand' called for [1, 2, 3]:Array (NoMethodError) > > So this argument would only affect methods calling rand from within instance > methods on Array or subclasses of it. I think the danger of overwriting > Kernel#rand in a way that would break user code is pretty low. I don't think it's terribly unlikely that someone will have a subclass like this: class Array def rand "o hai" end end class Foo < Array def bar rand(20) end end puts Foo.new.bar But since I pretty much loathe the idea of subclassing core classes, I don't mind breaking them :) -greg -- Technical Blaag at: http://blog.majesticseacreature.com | Non-tech stuff at: http://metametta.blogspot.com