From: Josh Cheek Date: 2010-07-07T19:02:05+09:00 Subject: Re: Hashes don't allow preceding commas by design? --001636457afee40dc0048ac94221 Content-Type: text/plain; charset=ISO-8859-1 On Wed, Jul 7, 2010 at 4:36 AM, Peter Hickman < peterhickman386@googlemail.com> wrote: > On 7 July 2010 10:15, Josh Cheek wrote: > > However, these examples have me so unsure of what is supposed to be what > > that I can't construct a response illustrating this. Please double check > > these examples. > > > > 1: => a = { :fred => 42 } > Okay, I found the point of confusion. The confusion is that "1: => " is not trying to create a hash table, but is rather a way of identifying line numbers. I was opening irb in all my different rubies seeing if it would accept { 1: => a = { :fred => 42 } } > 1: => a = > 2: => { > 3: => :fred => 42 > 4: => } > > Here line 1 is incomplete so it treats line 2 as a continuation. Line 2 > says > 'here is the start of a hash' and is also incomplete. So line 3 is seen as > a > continuation of line 2. > Line 3 is complete in that it is a valid statement that can be found inside > a hash declaration but the parser is still looking for the closing } to > match the opening { from line 2. So although line 3 is a complete valid > statement it is part of lines 1 and 2 which is an incomplete hash > declaration. > > So line 4 is taken to be a continuation of lines 1, 2 and 3 and finally > completes the statement that started on line 1. > Your explanation implies to me that the OP's desired use case is valid. If "line 4 is taken to be a continuation of lines 1, 2 and 3" then how come line 4 can't be ",:jim => 43" --001636457afee40dc0048ac94221--