# String of Parameters used as parameter list

**URL:** <https://www.ruby-forum.com/t/string-of-parameters-used-as-parameter-list/176964>\
**Category:** Ruby\
**Created:** [October 9, 2009, 2:39am UTC](https://www.ruby-forum.com/t/string-of-parameters-used-as-parameter-list/176964 "2009-10-09T02:39:24Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![jspencer78](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/f14d63/32.png) [@jspencer78](https://www.ruby-forum.com/u/jspencer78)\
**Post date:** [October 9, 2009, 2:39am UTC](https://www.ruby-forum.com/t/string-of-parameters-used-as-parameter-list/176964/1 "2009-10-09T02:39:24Z")

</div>

Hi there,

I know this might sound unorthodox but I am storing a function and  
parameters in a database for a particular set of class methods. Most of  
the functions have the same arguments but a few others have extra  
parameters after.

So instead of having a separate column for each parameter I am instead  
putting all the parameters in a single database column which I want to  
pass so I would like to do something like this:

class Klass  
def self.some\_function(age, weight, name); end  
end

function\_name = “some\_function”  
function\_args = “12, 14, ‘james’”  
Klass.send function\_name, function\_args

Is there any way to do this? I have looked at things like \*args but I  
would really like to keep the signature of the function the same because  
it’d require a lot of refactoring otherwise.

Cheers,  
James

---

<div class="post-metadata">

**Author:** ![jspencer78](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/f14d63/32.png) [@jspencer78](https://www.ruby-forum.com/u/jspencer78)\
**Post date:** [October 9, 2009, 3:49am UTC](https://www.ruby-forum.com/t/string-of-parameters-used-as-parameter-list/176964/2 "2009-10-09T03:49:44Z")

</div>

On Fri, Oct 9, 2009 at 8:39 AM, James S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:  
…

> function\_name = “some\_function”  
> function\_args = “12, 14, ‘james’”  
> Klass.send function\_name, function\_args
> 
> Is there any way to do this? I have looked at things like \*args but I  
> would really like to keep the signature of the function the same because  
> it’d require a lot of refactoring otherwise.

1 then you may need to adjust the calling, eg

> > Klass.send function\_name, \*function\_args.split(“,”)

2 or you can use eval or module\_eval also

kind regards -botp

---

<div class="post-metadata">

**Author:** ![jspencer78](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/f14d63/32.png) [@jspencer78](https://www.ruby-forum.com/u/jspencer78)\
**Post date:** [October 9, 2009, 4:29am UTC](https://www.ruby-forum.com/t/string-of-parameters-used-as-parameter-list/176964/3 "2009-10-09T04:29:30Z")

</div>

Great, thanks botp. I figured out the \* syntax about 10 minutes ago =)  
You were spot on with that though, thank you.

---

<div class="post-metadata">

**Author:** ![jspencer78](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/f14d63/32.png) [@jspencer78](https://www.ruby-forum.com/u/jspencer78)\
**Post date:** [October 9, 2009, 3:23pm UTC](https://www.ruby-forum.com/t/string-of-parameters-used-as-parameter-list/176964/4 "2009-10-09T15:23:57Z")

</div>

botp schrieb:

> 1 then you may need to adjust the calling, eg
> 
> > > Klass.send function\_name, \*function\_args.split(",")

The function\_args were two Fixnums and one String, after this you have  
“12” and " 14" instead of the numbers.

So you’d better put the args in an array (before they become Strings)  
and ‘Marshal.dump array’ this and later

Klass.send function\_name, \*Marshal.load(function\_args)

We should use eval when there is another way.

R.
