From: Gavin Kistner Date: 2005-05-19T12:01:14+09:00 Subject: Re: Noobie ... Simple Inheriting from Hash Question .. --Apple-Mail-3-725512346 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=US-ASCII; delsp=yes; format=flowed On May 18, 2005, at 7:01 PM, Neville Burnell wrote: >> Another option that hasn't been mentioned yet is to use delegation. >> You can have a wrapper around a hash that contains all your >> additional >> methods and references a Hash instance. > > Could you elaborate with code pls? class MyHash def initialize @hash = {} end # Do something special to the hash def square_all @hash.each{ |k,v| @hash[k] = v*v } end # Pass any method I don't understand on to the hash def method_missing(meth, *args, &block) @hash.send(meth, *args, &block) end end --Apple-Mail-3-725512346--