From: Robert Dober Date: 2010-04-18T02:58:07+09:00 Subject: Re: Undifined local variable or method error On Sat, Apr 17, 2010 at 7:30 PM, Simbolla Simbolla wrote: > Hi all, > > Below is my code > >  h={} >  arr=[] > def gethash >  h[1]=0 >  return h > end > arr[0]=gethash > puts arr[0].each {|k,v| puts "key #{k} value #{v}"} to my dismay def xxx... end is *not* a closure while define_method :xxx is IOW h is just not visible in def while it would if you define gethas via define_method be careful though on the toplevel you cannot use define_method, do something like include( Module::new do h = {} define_method :xxx do h.tap{ |hh| h[1] = 0 } end end ) puts xxx xxx[:a] = 42 puts xxx oh yes this code is ugly, but I wanted to demonstrate the semantics... HTH R. -- The best way to predict the future is to invent it. -- Alan Kay