From: "Iñaki Baz Castillo" Date: 2008-04-30T22:40:33+09:00 Subject: Re: How to create "def method(item)= (value)" ? 2008/4/30, Chris Hulan : > Why not just access param? > > class Foo > def initialize > @param = {} > end > attr_accessor :param > end > > x = Foo.new > x.param['key'] = 'bar' > > > If you do need to override it, the Hash assignment method is []= > So I think you can write: > def []=(key,value) > ... Because I need to give value to an attribute of a class containing the Hash @params, so the only way (AFAIK) is by creating an abstraction layer and handling the Hash @params via current class methods. This is my case: class Uri # Atributes: @modified => true/false @params => Hash attr_accessor :modified #what I want but it's not possible: def param(name)= (value) @params[name] = value @modified = true end end I can't do it by extending Hash class since inside Hash class I can't modify @modified attribute. Also note there are more ways than "=" to modify a Hash value: @params[name].strip! , .chomp! , .downcase! ...... and I don't want to redefine all of them so I just want to allow "=" and when it's called @modifed must be true. Hope I've explained why attr_accessor is not useful for me in this case. Thanks a lot. -- Iñaki Baz Castillo