From: Robert Klemme Date: 2004-09-04T19:30:15+09:00 Subject: Re: OK... :) question about hash and array literals "Hal Fulton" schrieb im Newsbeitrag news:41393C84.9090002@hypermetrics.com... > It has always bothered me a little that [...] and {...} do not > call Array.new and Hash.new respectively. > > I assume this is handled closer to parse time, for speed? > > Is there a method that does get called (I think not), or could > in theory such a thing be implemented? > > Example: > > class Hash > def Hash.literal(*pairs) > pairs.each do |pair| > k, v = pair > puts "Adding key #{k}, value #{v}" > end > super # or whatever > end > end > > x = {1=>2, 3=>4} # Output: Adding key 1, value 2 > # Adding key 3, value 4 > > And yes, this is related again to my wanting an ordered arbitrarily > indexable collection with a convenient literal notation. Even if a ordered map would be added you would not want to change literals default behavior. Too much code depends on this. I remember, we had a similar discussion with String literals a while ago. See also my post in the other thread. Kind regards robert