operator out of string

K

kelt

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
 
M

Marc Heiler

kelt said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,813
Messages
2,569,696
Members
45,480
Latest member
CrazyMember

Latest Threads

Top