From: Rick DeNatale Date: 2009-04-09T23:44:53+09:00 Subject: Re: Hash questions --00163628360a4d5b140467204ad6 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit On Thu, Apr 9, 2009 at 10:35 AM, Adam Gardner wrote: > > > From what I can tell, ruby is interpreting the beginning of your hash as > > the beginning of a block, instead; > > p({"foo" => 1, "bar" => 2, "baz" => 3 }) works as intended. > > > > This is seems like a bug to me, although whether it's a bug with the > > parser (finding a block where it should be looking for a hash literal), > > a bug with p (asking for a block when it doesn't use one) or the > > documentation (failing to mention that p accepts a block), I'm not sure. > > Actually, on a bit more inspection, both puts and print work the same > way, and I imagine there are other methods that do this as well. This > just seems like the parser failing to correctly interpret the ambiguity > of a {. > No, I'd say that the parser is correctly parsing an initial '{' after a method invocation as a block argument to the invocation. There's no need to mention that p, or any other method can be given a block since ANY ruby method can be given (and by default) ignore a block. It's just part of the language that you need to learn, like the need to use self.x = value to invoke an attribute writer method to disambiguate between x= as a method and x as a local variable. -- Rick DeNatale Blog: http://talklikeaduck.denhaven2.com/ Twitter: http://twitter.com/RickDeNatale WWR: http://www.workingwithrails.com/person/9021-rick-denatale LinkedIn: http://www.linkedin.com/in/rickdenatale --00163628360a4d5b140467204ad6--