m4dc4p wrote:
> I am trying to figure out how I can modify the Hash object so that I
> am notified each time a key is inserted in a Hash when it is
> constructed using the syntax below:
>
>   a = { "x" => "1", "y" => "2" }
>
> I've tried overriding []=, but that will only get called when the Hash
> is constructed explicitly.
>
> Here's a little bit of code showing what I've tried and the output I'd
> like to see. Thanks for any help!

<snip/>

> p.s. I'm ultimately doing this to get to an OrderedHash. I looked at
> Ara's code but the problem is I need to *replace* the functionality of
> Hash - it's not an option for me to explicitly create an OrderedHash
> object.

It's usually difficult to fiddle with built in classes as they employ some
optimizations.  What's the problem with replacing "h = {1=>2, 3=>4}" by "h
= OrdererdHash.create(1=>2, 3=>4)"?  Note that if you manipulate the hash
constructor {} you'll affect *all* hashes created in your app and libs -
something which might produce side effects (even if it's "only"
performance) you don't want.

My 0.02 EUR: stick with the explicit approach and drop manipulating built
in constructs.

Kind regards

    robert