From: nobu.nokada@... Date: 2003-01-06T00:01:31+09:00 Subject: Re: executing block at toplevel from within a class Hi, At Sun, 5 Jan 2003 22:41:57 +0900, Tom Sawyer wrote: > > > a = AnyOld.new > > > puts goneup > > > > > > reports goneup dosen't exist. where did it go? mind you i'm running this > > > from with in an rhtml eruby script. > > > > puts eval("goneup") > > that's odd. can get to it through eval but not otherwise? ugh, so is there no > way to dynamically define a toplevel local variable? that's basically what > i'm trying to do. No. Local variables (and constants now) are defined lexically. You can add methods dynamically. module Kernel def metaclass_eval(&block) (class << self; self; end).class_eval(&block) end end class AnyOther end class AnyOld def initialize goingup = AnyOther.new eval("self", TOPLEVEL_BINDING).metaclass_eval do define_method(:goneup, proc {goingup}) end end end a = AnyOld.new puts goneup -- Nobu Nakada