Charles L. Snyder wrote: > Why does this not work? > > doc = File::open("my.txt") > class Crap > def junko > @doc = doc > @doc.each {|line| print line} > end > end > myobj=Crap.new > myobj.junko Please note that class Foo ... end does indeed open a new scope that is totally disconnected to the scope that surrounds it in the source file. This basically means that you could workaround the issue with this: File.open("my.txt") do |doc| Crap = Class.new do def junko doc.each { |line| print line } end end end In Ruby it is /not/ considered good style do conditionally define classes which is probably the reason why the source code you tried to use above is discouraged.