From: gwtmp01@... Date: 2005-10-28T23:03:01+09:00 Subject: Re: Argument Passing Syntax On Oct 28, 2005, at 5:24 AM, Sean O'Halpin wrote: > On 10/27/05, gwtmp01@mac.com wrote: > >> Why are arguments to the '[]' method parsed differently >> than a standard method? >> > > Because () and [] are parsed differently. [] is primarily an array > reference (aref). But *why* are they parsed differently? Just "because"? For example, the common technique of aliasing :[] to :new means you can't expect to have ruby parse a trailing hash in the argument list when the method is called via :[] but you can when called via :new. I understand that the :[] method syntax has a different evolutionary path than the standard method syntax but is that the only reason that the arguments are parsed differently? > You can't pass blocks either in 1.8. In 1.9 you will be able to do > this: > o[1,2,3] { |x| p x } # this causes syntax error in 1.8 but works > in 1.9 Makes sense. I vote to extend the change to allow: o[1,2,3,:key => val] Note, you can already have an implicit literal hash, you just can't precede it with other arguments. o[:key => val] # OK now. o[1,2,3] # OK now. o[1,2,3,:key=>val] # bad now. Gary Wright