# Applying a random method to an object

**URL:** <https://www.ruby-forum.com/t/applying-a-random-method-to-an-object/127515>\
**Category:** Ruby\
**Created:** [January 29, 2008, 11:19pm UTC](https://www.ruby-forum.com/t/applying-a-random-method-to-an-object/127515 "2008-01-29T23:19:01Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![bor\_S](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/0ea827/32.png) [@bor\_S](https://www.ruby-forum.com/u/bor_S)\
**Post date:** [January 29, 2008, 11:19pm UTC](https://www.ruby-forum.com/t/applying-a-random-method-to-an-object/127515/1 "2008-01-29T23:19:01Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![bor\_S](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/0ea827/32.png) [@bor\_S](https://www.ruby-forum.com/u/bor_S)\
**Post date:** [January 29, 2008, 11:24pm UTC](https://www.ruby-forum.com/t/applying-a-random-method-to-an-object/127515/2 "2008-01-29T23:24:38Z")

</div>

Boris S. 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)
