From: "E. Saynatkari" Date: 2006-03-03T06:21:37+09:00 Subject: Re: Confusion Over Keyword Arguments Daniel Berger wrote: > Yukihiro Matsumoto wrote: >> >> >> foo(1, foo:3) # (a=1, b={:foo=>3}) or (a=1,b=0,c=[{:foo=>3}])? > > Error. There's no 'foo' parameter. Passing a literal hash would > require {}. > >> foo(1, 2, 8, c:5) # c={:c=>5}) or c=[8,{:c=>5}] or error? > > Hm. Either an error or c = [5], depending on whether or not your want > to > declare that, once a positional is used, there's no going back after the > fact. > >> args = [1, {:b=>2, foo=>5}] >> foo(*args) # (a=1,b={:b=>2, foo=>5}) or (a=1,b=2,c=[{:foo=>5}])? > > a = 1, b = {:b=>2, foo=>5}, since you've passed a literal hash. > > Here's the latest test case we had for Sydney. Note that Sydney assumes > that > all method arguments automatically become keyword arguments. There's no > syntax > for explicitly declaring that a given method parameter is a valid > keyword argument. > > For the kids following along at home, also see > http://redhanded.hobix.com/inspect/namedParametersArenTTheyAllNamed.html > for > further discussion on the subject. > > Regards, > > Dan Slightly off-topic but I found this part curious: > # You can use named parameters, using the name of the parameter defined in > # in the method itself. It must be the name of the parameter, followed by > # a colon, followed by the value. Spaces between the parameter name, colon > # and value are not allowed. Why is this? foo: bar would seem to be more legible with the added benefit of no confusion with the scope operator :: nor Symbols. Your testcases do not seem to cover the scope completely and Symbols are not included at all. Maybe add something like def test_corner_cases() # Symbols assert_nothing_raised {@foo.bar x:1, y:2, z::symbol} # Scopes assert_nothing_raised {@foo.bar A::B, y:2, z:3} assert_nothing_raised {@foo.bar x:1, y:2, z:::Object} assert_nothing_raised{ @foo.bar(z:1, x:2, y:3) } end # test_corner_cases To cover those. > < snip rest of test cases /> E -- Posted via http://www.ruby-forum.com/.