From: Gennady Bystritsky Date: 2010-04-14T01:01:25+09:00 Subject: Re: scope limitation causes problems for me. On Apr 13, 2010, at 8:41 AM, ±èÁØ¿µ wrote: > hi, everyone. > > I have the following codes. > > m = Hash.new("merong") > > m["b"] = "babo" > > def func > begin > m["a"] = "merong" > rescue => e > puts e > end > end > > func > > > > exception is > > undefined local variable or method `m' for main:Object > > Could I know the reason this was caused?? In your code, m is defined as a local variable in the top scope, so it is not visible in methods. A straightforward fix would be to use $m instead of m, which will designate a global variable. However, I would strongly recommend to wrap your code in a class and have an instance variable @m which will be visible to every method of that class, thus avoiding evil global variables: class Performer def initialize(default_value) @m = Hash.new(default_value) @m["b"] = "babo" end def func begin @m["a"] = "merong" rescue => e puts e end end end Then you can call it as: Performer.new("merong").func Gennady.