I tried to create an addition to Enumerable called choose_randomly
that picks a random element from the Enumerable object. However when I
define it and execute the code rand complains about the wrong number
of arguments. Below is a capture of the ./script/console session.
[email protected] ~/Work/GreenGreen/Code/green_green_client_application
Loading development environment (Rails 2.1.2)
NoMethodError: undefined method `choose_randomly’ for [1, 2, 3]:Array
array_of_self = Array( self )
index = rand( array_of_self.size )
array_of_self[ index ]
ArgumentError: wrong number of arguments (1 for 0)
rand' from (irb):5:inchoose_randomly’
[1,2,3][ rand( [1,2,3].size )]
As you can see if I execute the code myself it seems to work. If I
copy that same code into irb it works perfectly.