From: "Bartosz DziewoƄski" Date: 2012-08-06T03:19:20+09:00 Subject: Re: Redefining constants for a given instance only Sooo... how badly do you need this? Because if the answer is "very badly", then you could do this: (If someone asks, I didn't recommend this. The code that follows is braindead, wrong on multiple levels, and *will* fail in unpredictable ways in production. You have been warned.) class ClassA end class ClassB end class Evaluator def evaluate # to make the source more interesting if true return ClassA else return nil end end end ev = Evaluator.new ev2 = Evaluator.new file, line = ev.method(:evaluate).source_location lines = File.readlines(file) indent = lines[line-1][/^\s*/] source_lines = lines.drop(line).take_while{|ln| ln=~/#{indent}\s/o } source = lines[line-1] + source_lines.join("\n") + "end\n" # this could be done better, but anything reasonable involving singleton_class failed on me eval "class< ClassB puts ev2.evaluate #=> ClassA -- Matma Rex