From: "Jesús Gabriel y Galán" Date: 2009-12-19T07:15:23+09:00 Subject: Re: loses scope? On Fri, Dec 18, 2009 at 11:06 PM, Roger Pack wrote: > Anybody know why this fails? > > a = 32 > class A >  def go >  a >  end > end > puts A.new.go # raises with "a not defined" > > ? Because both "class" and "def" keywords create a new scope. They are not closures, they don't see their surrounding scope. Consider this other way, which doesn't create new scopes: irb(main):001:0> a = 3 => 3 irb(main):008:0> Test = Class.new do irb(main):009:1* define_method(:go) do irb(main):010:2* puts a irb(main):011:2> end irb(main):012:1> end => Test irb(main):013:0> Test.new.go 3 => nil Jesus.