2011/10/26 Jes=FAs Gabriel y Gal=E1n <jgabrielygalan / gmail.com>:
> On Wed, Oct 26, 2011 at 4:28 PM, Peter Vandenabeele
> <peter / vandenabeele.com> wrote:
>> 2011/10/26 Jes=FAs Gabriel y Gal=E1n <jgabrielygalan / gmail.com>

>> 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 cleane=
r.
> 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


--=20
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/