# Operator out of string

**URL:** <https://rubytalk.org/t/operator-out-of-string/45937>\
**Category:** ruby-talk\
**Created:** [17 April 2008 07:15 UTC](https://rubytalk.org/t/operator-out-of-string/45937 "2008-04-17T07:15:05Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![kelt](https://avatars.discourse-cdn.com/v4/letter/k/ec9cab/32.png) [@kelt](https://rubytalk.org/u/kelt)\
**Post date:** [17 April 2008 07:15 UTC](https://rubytalk.org/t/operator-out-of-string/45937/1 "2008-04-17T07:15:05Z")

</div>

Hey,

I am a newbee in Ruby and since the language has many nice features it  
struck me obvioous that it must be possible to evaluate a string in  
such a way that it produces the corresponding operator. E.g.: "+"  
would become a simple plus sign, thus allowing me to pass "+" as a  
function to be done on two integers.

Thank you

kelt

---

<div class="post-metadata">

**Author:** ![Marc\_Heiler](https://avatars.discourse-cdn.com/v4/letter/m/e8c25b/32.png) [@Marc\_Heiler](https://rubytalk.org/u/Marc_Heiler)\
**Post date:** [17 April 2008 07:22 UTC](https://rubytalk.org/t/operator-out-of-string/45937/2 "2008-04-17T07:22:15Z")

</div>

kelt wrote:

> Hey,
> 
> I am a newbee in Ruby and since the language has many nice features it  
> struck me obvioous that it must be possible to evaluate a string in  
> such a way that it produces the corresponding operator. E.g.: "+"  
> would become a simple plus sign, thus allowing me to pass "+" as a  
> function to be done on two integers.
> 
> Thank you
> 
> kelt

2.send("+",5) # =\> 7

> **···**
>
> --  
> Posted via [http://www.ruby-forum.com/\](http://www.ruby-forum.com/%5C).

---

<div class="post-metadata">

**Author:** ![kelt](https://avatars.discourse-cdn.com/v4/letter/k/ec9cab/32.png) [@kelt](https://rubytalk.org/u/kelt)\
**Post date:** [17 April 2008 08:00 UTC](https://rubytalk.org/t/operator-out-of-string/45937/3 "2008-04-17T08:00:11Z")

</div>

Thank you very much Marc,

that was exactly what I was looking for.

> **···**
>
> On Apr 17, 3:22 am, Marc Heiler \<sheve...@linuxmail.org\> wrote:
> 
> > kelt wrote:  
> > \> Hey,
> > 
> > \> I am a newbee in Ruby and since the language has many nice features it  
> > \> struck me obvioous that it must be possible to evaluate a string in  
> > \> such a way that it produces the corresponding operator. E.g.: "+"  
> > \> would become a simple plus sign, thus allowing me to pass "+" as a  
> > \> function to be done on two integers.
> > 
> > \> Thank you
> > 
> > \> kelt
> > 
> > 2.send("+",5) # =\> 7  
> > --  
> > Posted viahttp://www.ruby-forum.com/.
