From: Robert Dober Date: 2009-04-22T18:08:32+09:00 Subject: Re: Is there a better way to do this? On Wed, Apr 22, 2009 at 12:57 AM, Paul Mckibbin wrote: > Robert Dober wrote: >> On Tue, Apr 21, 2009 at 11:40 PM, Robert Klemme >> wrote: >>> data. �If you have classes already for storing all this, I'd probably write >>>> or alternatively >>>> >>> def method_missing(sym,*args,&blk) >>> �self[sym] || self[sym.to_s] || super >> the following line will work for all potential hash values >> >>     fetch( sym ) { fetch( sym.to_s ) { super } } >> >> HTH >> Robert > > Cool and will generate the same error type, I've used a modification of > it to make the stack look the same, and give a debugging hint if it does > go wrong.... > > > begin >  fetch( sym ) { fetch( sym.to_s ) { super }} > rescue >  raise NoMethodError,"undefined method #{sym} for > #{self.inspect}:#{self.class} overridden by Mac's redefinition of > Hash::method_missing in #{__FILE__}" > end Hmm unless I am missing something here there is no need to raise NoMethodError with super just to rescue it immediately What about def method_missing sym fetch( sym ) do fetch( sym.to_s) do raise NoMethodError,"undefined method #{sym} for #{self.inspect}:#{self.class} overridden by Mac's redefinition of Hash::method_missing in #{__FILE__}" end end end Robert > > Thanks again, > > Mac > -- > Posted via http://www.ruby-forum.com/. > > -- Si tu veux construire un bateau ... Ne rassemble pas des hommes pour aller chercher du bois, préparer des outils, répartir les tâches, alléger le travail… mais enseigne aux gens la nostalgie de l’infini de la mer. If you want to build a ship, don’t herd people together to collect wood and don’t assign them tasks and work, but rather teach them to long for the endless immensity of the sea. -- Antoine de Saint-Exupéry