From: Jeremy Bopp Date: 2010-10-27T01:35:58+09:00 Subject: Re: require in instance_eval On 10/26/2010 7:54 AM, unexist wrote: > > Hello list, > > just wondered about following: http://pastie.org/1249746 > > Is this the intended behaviour of require? I am a bit surprised, that it evals the code on object-level > instead of staying in the scope of my Foobar object. You can call require from anywhere, be it within a class definition, a method, or even an eval statement. In all cases the general expectation is that require loads the file into the global namespace rather than into the scope of the calling code. > Is there a way around this? Have you tried loading the contents of the file as a string and then passing the string to eval rather than call require on the file? I think that might do what you want. > Also is it's possible to set the LOAD_PATH to get require_relative in > instance_eval to work? What exactly is the error message when you try to use require_relative? > I know about the path parameter of instance_eval, but apparently it doesn't > change anything. Yeah, that is only to supply a file name to be reported as the source file if there are problems that require a stack trace to be produced. It's not intended to help you load a file at all. -Jeremy