From: Austin Ziegler Date: 2007-10-02T21:07:04+09:00 Subject: Re: canonical Array#append to hang hook On 10/2/07, Lars Ticot wrote: > To Robert Klemme: > Sure I can do this but this way I lose every benefit of inheritance! And > I'll have to rewrite "accesor" function to access function to the > instance variable array. That is not very DRY. No you don't. #method_missing and #respond_to? are your friends. Or you can use Delegator. class NRArray def initialize(*args, &block) @nrarray = if args.empty? and block.nil? [] elsif args.empty? Array.new &block else Array.new(*args, &block) end end def respond_to?(sym) ok = super ok = @nrarray.respond_to?(sym) unless ok ok end def method_missing(sym, *args, &block) puts "#{sym}ing #{args.inspect}" @nrarray.send(sym, *args, &block) end end (Note that NArray is a well-known numerical array extension, so Narray is likely to be confusing if you need it.) -austin -- Austin Ziegler * halostatue@gmail.com * http://www.halostatue.ca/ * austin@halostatue.ca * http://www.halostatue.ca/feed/ * austin@zieglers.ca