I have a class that extends Hash, and I want to track when a hash key is modified.
What's the right syntax to override the [key]=
syntactic method to accomplish this? I want to insert my code, then call the parent method.
Is this possible with the C methods? I see from the docs that the underlying method is
rb_hash_aset(VALUE hash, VALUE key, VALUE val)
How does that get assigned to the bracket syntax?
I think using
set_trace_func
is more general solutionThe method signature is
def []=(key, val)
, andsuper
to call the parent method. Here's a full example: