[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

operator out of string

kelt

4/17/2008 7:14:00 AM

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 Answers

Marc Heiler

4/17/2008 7:22:00 AM

0

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-....

kelt

4/17/2008 7:58:00 AM

0

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-....