From: Robert Klemme Date: 2011-10-27T00:02:36+09:00 Subject: Re: Modify only a .rb file, but not other .rb files, while still extending core classes? 2011/10/26 Jesús Gabriel y Galán : > On Wed, Oct 26, 2011 at 4:28 PM, Peter Vandenabeele > wrote: >> 2011/10/26 Jesús Gabriel y Galán >> I think an equivalent way is to directly open the singleton class of a >> (what extend is doing in your implementation). > > Sure, but if you need it in several arrays, the module approach is cleaner. > And I'd say that even for one array is cleaner too :). Not only that: I'd expect it to use less resources, too. Reason is that there is just one definition of the method. Plus, it's easier to later change it for all Array instances if that should be needed. Marc, we do not know what your method #rand does and which Ruby version you are using, but since 1.9 there is Array#sample which might be exactly what you are looking for. Kind regards robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/