From: Robert Klemme Date: 2009-04-22T15:25:05+09:00 Subject: Re: Is there a better way to do this? On 22.04.2009 00:26, Paul Mckibbin wrote: > Robert Klemme wrote: >> If I understand the rest of your post correctly it is not exactly the >> same structure but rather similarly structured data in two different >> data structures (custom classes and XML DOM). > > True, but it is a 3rd party object library that I don't have access to > other than through OLE calls or file storage. I see. But: if file storage means XML then you can still create a data structure which responds to the same set of methods as the OLE version. An alternative approach to modifying Hash is to wrap the whole beast in something that exhibits the same interface as the OLE version. require 'delegate' class HashWrap < SimpleDelegator def method_missing(s,*a,&b) key = s.to_s if a.empty? and __getobj__.key? key res = __getobj__[key] res = self.class.new(res) if Hash === res res else super end end end h = {"foo" => {"x"=>456}, "bar" => 2} s = HashWrap.new h p s.foo p s.foo.x p s.bar p s.not_there Cheers robert