From: Hal Fulton Date: 2006-10-19T08:55:27+09:00 Subject: Re: My first feeling of Ruby Florent Guiliani wrote: > > Why #test doesn't work for local variables? It would be more logic. It's > my point of view. We can have both #test and #{test} working. > For one thing, test could just as easily be a method name. This might lead people to think that the parameters followed it in the string. Things such as #$foo and #@foo are special cases. A single char tells us that it's a simple variable. The general case is #{...} and can be any arbitrary expression. > Second thing: > ============= > hastables is using a mix of {} and []. Always using {} or [] (but not > both) for hastable would be "errorless". Conflict with block syntax. You can't say hash {"A"} meaningfully. In fact, I'm not certain why that returns an integer. Hal > Actually {} for initialisation: > irb(main):150:0> hash = { "A"=>1 , "B"=>2 } > => {"A"=>1, "B"=>2} > > [] for reading: > irb(main):152:0> hash["A"] > => 1 > > If you go wrong: > irb(main):156:0> hash{"A"} > => 537984250 > irb(main):154:0> hash = [ "A"=>1 , "B"=>2 ] > => [{"A"=>1, "B"=>2}] > > I would prefer an error or warning. The last line means I can omit {}? > so let's go on: > > irb(main):155:0> hash = "A"=>1 , "B"=>2 > SyntaxError: compile error > (irb):155: parse error, unexpected tASSOC, expecting $ > hash = "A"=>1 , "B"=>2 > ^ > from (irb):155 > from :0 > irb(main):156:0> > > Hmm why [ "A"=>1 , "B"=>2 ] silently produce [{"A"=>1, "B"=>2}] ? > > my 2c, > Florent, >