treating 'string'+var as method

B

bmgz

I am a new Ruby recruit (thanks to *ahem*, Rails)..
What is the best way to do this:

* obj.'string'+var as a method?

I am currently using:

* obj.send('string'+var)

...which works fine, but is this correct or bad practice?
 
R

Robert Klemme

bmgz said:
I am a new Ruby recruit (thanks to *ahem*, Rails)..
What is the best way to do this:

* obj.'string'+var as a method?

I am currently using:

* obj.send('string'+var)

..which works fine, but is this correct or bad practice?

That's ok. As Ross pointed out you can also use obj.send("string#{var}").
But I would not use eval - there's just too much that can go wrong
security wise.

Kind regards

robert
 

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
474,201
Messages
2,571,048
Members
47,647
Latest member
NelleMacy9

Latest Threads

Top