From: Jim Freeze Date: 2006-02-27T03:33:44+09:00 Subject: Re: Scope of constants in instance_eval On Feb 26, 2006, at 12:08 PM, Phrogz wrote: > Jim Freeze wrote: >> Hmm, that could be a bug in ruby because >> >> p BAR >> >> works. > > Hrm? Not on my machine. Hmm, even more interesting. Change the following: > > class Foo > BAR = 1 > def initialize( &block ) def initialize(str) > instance_eval &block instance_eval str > end > def bork > puts "bork: self is #{self}" > puts "bork: BAR is #{BAR}!" > end > end > > Foo.new{ Foo.new %Q{ > bork > puts "block: self is #{self}" > #puts "block: BAR is #{BAR}!" > p BAR > } > Now what do you get? > #=> bork: self is # > #=> bork: BAR is 1! > #=> block: self is # > #=> NameError: uninitialized constant BAR > > Jim Freeze