[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

applying a random method to an object

Boris Schmid

1/29/2008 10:19:00 PM

A weblog showed that .methods could be sorted and behaved like an array
(which I had not noticed before).

Now I'm trying (somewhat unsuccesfully) to find a way (including google
and the ruby doc) to apply for example a randomly selected method to an
object.

example:
array = [:to_s,:next,:to_f]
15.array.shuffle.first

but this doesn't work. Is there a way?
--
Posted via http://www.ruby-....

1 Answer

Joel VanderWerf

1/29/2008 10:23:00 PM

0

Boris Schmid wrote:
> A weblog showed that .methods could be sorted and behaved like an array
> (which I had not noticed before).
>
> Now I'm trying (somewhat unsuccesfully) to find a way (including google
> and the ruby doc) to apply for example a randomly selected method to an
> object.
>
> example:
> array = [:to_s,:next,:to_f]
> 15.array.shuffle.first

Use the #send method:

15.send(array.shuffle.first)


--
vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407