matu
7/27/2008 2:44:00 PM
Stefan Buhr wrote:
> Hi there,
>
> I want to do this:
>
> @myclass.items[5] = an_item
>
> But the items object of @myclass should have an custom setter. I have
> tried this:
> class Myclass
> def items
> def []= value
> -code-
> end
> end
> end
>
> but this does not work. How can i do that?
>
class MyArray < Array
def []= index, value
super
p 'hi'
end
end
class Myclass
attr_accessor :items
end
m = Myclass.new
m.items = MyArray.new
m.items[5] = "blah"