You declared set_prop
, but you're using []=
in tests. Did you mean to get this?
class MyClass
attr_accessor :my_hash
def initialize(hash={})
@my_hash = hash
end
def [](key)
my_hash[key]
end
def []=(key, value)
my_hash[key] = value
end
end
test = MyClass.new({:a => 3}) # success
test[:a] # success
test[:b] = 4 # success
test.my_hash # => {:a=>3, :b=>4}