Rassat Nicolas wrote:
> I have a class which inherit from Array. I want to perform some task
> each time something is append to an instance of this class. The problem
> is: there are so many way to append something to an array. For example:
> 
> class Narray < Array
...
>   alias_method :old_add, :+
>   def +(i)
>     p "+ing #{i}"
>     old_add(i)
>   end
> end

It's not clear to me (though maybe it is clear to you) whether + should 
be considered as a kind of append operation. Note that + doesn't modify 
the array, but returns a new array. Furthermore, + doesn't return an 
instance of NArray, but just an Array:

irb(main):001:0> class A < Array
irb(main):002:1>   def +(x); super; end
irb(main):003:1> end
=> nil
irb(main):004:0> a = A.new
=> []
irb(main):005:0> (a + []).class
=> Array

However:

irb(main):008:0> (a.concat []).class
=> A

-- 
        vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407