Joerg Diekmann
2006-Aug-10 11:44 UTC
[Rails] 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 -- Posted via http://www.ruby-forum.com/.
choonkeat
2006-Aug-10 12:49 UTC
[Rails] Passing parameters defined in a function or something
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 On 8/10/06, Joerg Diekmann <joergd@pobox.com> wrote:> > 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 > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060810/7b2c2c50/attachment-0001.html