I feel like this is a dumb question....

C

Chris Hickman

I am trying to call a method where the name is based on a parameter.

For example: if sec_id = 1 I want to call template1
if sec_id = 2 I want to call template2 ...

Without doing if else statements, which is not reasonable for the amount
of possible sec_id's, is there a way to say something like template and
concatenate on the sec_id? to get template1, template2, template...

I know you can do this to get string concatenation but I can't seem to
use that at all as a method name, just a string.


Thanks in advance,


Chris
 
J

James Gray

I am trying to call a method where the name is based on a parameter.

For example: if sec_id = 1 I want to call template1
if sec_id = 2 I want to call template2 ...

Without doing if else statements, which is not reasonable for the
amount
of possible sec_id's, is there a way to say something like template
and
concatenate on the sec_id? to get template1, template2, template...

Sure:

obj.send("template#{sec_id}")

Hope that helps.

James Edward Gray II
 
J

Joel VanderWerf

Chris said:
I am trying to call a method where the name is based on a parameter.

For example: if sec_id = 1 I want to call template1
if sec_id = 2 I want to call template2 ...

Without doing if else statements, which is not reasonable for the amount
of possible sec_id's, is there a way to say something like template and
concatenate on the sec_id? to get template1, template2, template...

send "template#{sec_id}"
 
C

Chris Hickman

awesome, I have used the string concatenation in rails for links and
action calls but never needed it for this. Thanks a lot

Chris
 

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

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top