On May 8, 2006, at 4:16 PM, Victor Shepelev wrote: > > > From: Logan Capaldo [mailto:logancapaldo / gmail.com] >> On May 8, 2006, at 4:05 PM, Philip Hallstrom wrote: >> >>> Hi - >>> >>> For a variety of reasons I have the following situation: >>> >>> ---- file_a.rb -------------------------------------- >>> class A >>> ... magic loading goes here... >>> end >>> -------------------------------------------------- >>> >>> ---- file_b.rb -------------------------------------- >>> class B >>> ... magic loading goes here... >>> end >>> -------------------------------------------------- >>> >>> ---- magic_file.rb ----------------------------- >>> ... does some stuff... >>> ---------------------------------------------- >>> >>> How can I include the contents of magic_file.rb into both a and b >>> "as is". >>> ... >>> >>> -philip >>> >> >> class A >> eval(File.read("magic_file.rb")) >> end >> > > Interesting solution. What about its effectivenes? And in general, > effectivenes of require'ing something vs. eval'ing it? > > Victor > > Well require-ing only parses the file once. Other than that, this takes more memory (since it puts the entire file inside a string) but other than that I'm pretty sure the difference is effectively zero. The 'ideal' solution to this problem would be if load took an optional binding argument e.g.: class A load("magic_file.rb", false, binding) end