From: Yukihiro Matsumoto Date: 2005-10-22T12:12:05+09:00 Subject: Re: A comparison by example of keyword argument styles Hi, In message "Re: A comparison by example of keyword argument styles" on Sat, 22 Oct 2005 00:44:58 +0900, Daniel Berger writes: |> def foo(*args) |> # how do you delegate arguments? |> bar(*args) |> end |> |> def bar(a,b,c) |> p [a,b,c] |> end |> |> foo(1,a:2,c:3) | |Not allowed because redefinition of the same parameter raises an error. Here |you're trying to define 'a' twice, once as the first positional argument, once |as a named parameter. Then what if foo(1,b:2,c:3) ? |Yes, it's uglier. How does it work in your implementation? I'm curious to know |how you preserve argument order. For mine, args in foo becomes [1,{:a=>2,:c=>3}]. And suppose def bar(a:,b:,c:) p [a,b,c] end since it requires explicit keyword arguments, delegation should be plain bar(*args) and bar prints [1,2,3]. |Let me ask you the same thing. What happens here with your implementation? | |class Foo | def foo(a:, b:, c:) | p [a,b,c] | end |end | |class Bar < Foo | def foo(d:, e:, f:) | super | end |end | |Bar.new.foo(f:3, e:2, d:1) Bar#foo receives [{:f=>3,:e=>2,:d=>1}], then it delegates arguments to Foo#foo. Foo#foo accepts keyword arguments a, b, c, and no other keywords (it does not have ** in the list), it raises ArgumentError. matz.