From: Stefano Crocco Date: 2008-02-26T23:19:46+09:00 Subject: Re: # arguments to rand Alle Tuesday 26 February 2008, d c ha scritto: > 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 It works for me. By the way, you don't need the to_i in the call to rand: Array#size is already and integer. Stefano