# I feel like this is a dumb question

**URL:** <https://www.ruby-forum.com/t/i-feel-like-this-is-a-dumb-question/127935>\
**Category:** Ruby\
**Created:** [February 2, 2008, 9:43pm UTC](https://www.ruby-forum.com/t/i-feel-like-this-is-a-dumb-question/127935 "2008-02-02T21:43:28Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![bigdaddy71](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/bbe5ce/32.png) [@bigdaddy71](https://www.ruby-forum.com/u/bigdaddy71)\
**Post date:** [February 2, 2008, 9:43pm UTC](https://www.ruby-forum.com/t/i-feel-like-this-is-a-dumb-question/127935/1 "2008-02-02T21:43:28Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![bigdaddy71](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/bbe5ce/32.png) [@bigdaddy71](https://www.ruby-forum.com/u/bigdaddy71)\
**Post date:** [February 2, 2008, 9:51pm UTC](https://www.ruby-forum.com/t/i-feel-like-this-is-a-dumb-question/127935/2 "2008-02-02T21:51:18Z")

</div>

On Feb 2, 2008, at 2:43 PM, Chris H. wrote:

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

---

<div class="post-metadata">

**Author:** ![bigdaddy71](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/bbe5ce/32.png) [@bigdaddy71](https://www.ruby-forum.com/u/bigdaddy71)\
**Post date:** [February 2, 2008, 9:53pm UTC](https://www.ruby-forum.com/t/i-feel-like-this-is-a-dumb-question/127935/3 "2008-02-02T21:53:03Z")

</div>

Chris H. wrote:

> 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}”

---

<div class="post-metadata">

**Author:** ![bigdaddy71](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/bbe5ce/32.png) [@bigdaddy71](https://www.ruby-forum.com/u/bigdaddy71)\
**Post date:** [February 2, 2008, 9:54pm UTC](https://www.ruby-forum.com/t/i-feel-like-this-is-a-dumb-question/127935/4 "2008-02-02T21:54:14Z")

</div>

obj.send(“template#{sec\_id}”)

---

<div class="post-metadata">

**Author:** ![bigdaddy71](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/bbe5ce/32.png) [@bigdaddy71](https://www.ruby-forum.com/u/bigdaddy71)\
**Post date:** [February 2, 2008, 9:54pm UTC](https://www.ruby-forum.com/t/i-feel-like-this-is-a-dumb-question/127935/5 "2008-02-02T21:54:28Z")

</div>

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

Chris
