Passing parameters defined in a function or something

Hi,

I have method I want to call … it can receive * number of parameters.

I also have 3 parms that I want to pass often, so I have defined them in
a separate function:

def my_params
{ :parm1 => 1, :parm2 => 2, :parm3 => 3 }
end

And I want to call my method like this:

mymethod :parm4 => 4, my_params

Now - this doesn’t work - as my_params is a hash of params, which isn’t
the same as calling

mymethod :parm4, :parm1 => 1, :parm2 => 2, :parm3 => 3

Pretty basic - yet fundamental. How do I solve this?

Thanks
Joerg

Looks like you’re only passing in 1 hash, so perhaps you can work with
this:

mymethod my_params.merge(:parm4 => 4)

Or perhaps I’ve misunderstood your requirements.


choonkeat

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs