From: "David A. Black" Date: 2010-04-18T03:26:34+09:00 Subject: Re: Undifined local variable or method error Hi -- On Sun, 18 Apr 2010, 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}"} > > For the above i get error saying "Undifined local variable or method 'h' > for main:Object(NameError)" > > may i know reason for this error? The def keyword starts a new local scope. The same happens with class: a = 1 class C puts a # new local scope, so a is not defined end David -- David A. Black, Senior Developer, Cyrus Innovation Inc. THE Ruby training with Black/Brown/McAnally COMPLEAT Coming to Chicago area, June 18-19, 2010! RUBYIST http://www.compleatrubyist.com