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.
Just curious...
Hal