From: Philip Hallstrom Date: 2006-05-09T06:23:32+09:00 Subject: Re: "load"ing a file and keeping the current scope? >>> 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". >>> I've tried load() and it changes the scope so that magic_file.rb doesn't >>> realize it's in A or B. >>> >>> I guess I'm looking for the PHP include() equivalent. >>> >>> I realize this is a weird question and I realize in most situations this >>> is *not* the way to do it, but I don't have a choice... so please no "do >>> it this other way" solutions :) >>> >>> Thanks! >>> >>> -philip >>> >>> >> >>> >> >> class A >> eval(File.read("magic_file.rb")) >> end That worked. Thanks! > I realize this is against your "no other solutions" rule, but why won't > > % cat magic_file.rb > module Stuff > ... > end > > % cat a.rb > class A > require 'magic_file' > include Stuff > end > > work? Not sure... (i'm fairly new to ruby) but I tried it and it doesn't. Here's specific details on what I'm doing (rails web services): http://www.ruby-forum.com/topic/65015#new -philip