I want to override my own Hash class brackets in ruby.
Note. I do not want to override them in a class that inherits from Hash (without a subclass), I want to actually override Hash, so any hash will always inherit my behavior.
In particular (bonus points for ..) - I want this to initially emulate a hash with indifferent access. In JavaScript, I would change prototype , Ruby is known for its metaprogramming, so I hope this is possible.
So what am I striving for:
>>
I tried: 1)
class Hash define_method(:[]) { |other| puts "Hi, "; puts other } end
and
class Hash def [] puts 'bar' end end
Both crash irb.
source share