From: Brian Candler Date: 2010-04-18T17:59:28+09:00 Subject: Re: Undifined local variable or method error Gavin Kistner wrote: > On Apr 17, 11:30�am, Simbolla Simbolla wrote: >> for main:Object(NameError)" > If you want h to be a global variable, accessible everywhere, prefix > it with a dollar sign: > > $h={} > def foo > $h[1]=0 > $h > end > foo > p $h > #=> {1=>0} But usually it would be better instead to: (1) pass h as an argument to method foo; or (2) define a class with instance variable @h -- Posted via http://www.ruby-forum.com/.