On Tue, Feb 26, 2008 at 3:14 PM, d c <lister / pikkle.com> wrote:
> hi -
>
>  can someone help with suggesting what is wrong below? i am trying to
>  add a simple method to array#random
>
>  but get the wrong number of args error...
>  have tried lots of variations!
>
>  >> class Array
>  >>   def random
>  >>     n = rand(self.size.to_i)
>  >>     return self[n]
>  >>   end
>  >> end
>  => nil
>  >> [1, 2, 3].random
>  ArgumentError: wrong number of arguments (1 for 0)
>         from (irb):14:in `rand'
>         from (irb):14:in `random'
>         from (irb):18
>  >> rand(3)
>  => 1
>  >> rand(3)
>  => 1
>  >> rand(3)
>  => 2
>
>
>  tx
>
>  /dc
>
>

Works for me.