Is there a way to do python's kwargs passthrough in ruby 1.9.3? -
so have functions in ruby 1.9 really, nice functional equivalent of this:
def foo(**kwargs): ...do stuff... def bar(**kwargs): foo(x = 2, y = 3, **kwargs)
so ruby has opts, if this:
def f(opts) print opts.keys end def g(opts) f(opts, :bar=>3) end g(:foo => 1)
i get:
script:1:in f': wrong number of arguments (2 1) (argumenterror) script:6:in g' script:9:in <main>'
is there way pass opts through g f?
your
def g(opts) f(opts, :bar=>3) end
passes 2 arguments f
. let pass one, this:
def g(opts) f(opts.merge(:bar=>3)) end
Comments
Post a Comment