From: Andrea Dallera Date: 2012-08-06T02:19:08+09:00 Subject: Redefining constants for a given instance only --_=__=_XaM3_.1344186742.2A.164376.42.1475.52.42.007.104103821 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Hello,=0A=0A=C2=A0 =C2=A0 let's say we have two empty classes:=0A=0Aclass= ClassA=0A=0Aend=0A=0Aclass ClassB=0A=0Aend=0A=0Athen we have a third one= , which has a method that references the first class:=0A=0Aclass Evaluato= r=0A=C2=A0 =C2=A0=0A=C2=A0 =C2=A0def evaluate=0A=C2=A0 =C2=A0 =C2=A0 =C2=A0= return ClassA=0A=C2=A0 =C2=A0end=0A=0Aend=0A=0AWhat I'd like to do is to = be able to redefine what ClassA is for a given instance of Evaluator, lik= e so:=0A=0Aev =3D Evaluator.new=0A=0Aev.evaluate #ClassB=0A=0AI found out how to do this, but = only class-wide:=0A=0Aev =3D Evaluator.new=0Aev.evaluate #ClassA=0Aclass = Evaluator=0A=C2=A0 ClassA =3D ClassB=0Aend=0Aev.evaluate #ClassB=0A=0AIde= as?=0A=0AAndrea=0A=0A=C2=A0=0A--=0A=C2=A0=0Ahttp://usingimho.wordpress.co= m=0Ahttp://github.com/bolthar --_=__=_XaM3_.1344186742.2A.164376.42.1475.52.42.007.104103821 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: quoted-printable =0A
=0A
Hello,

  &= nbsp; let's say we have two empty classes:

class= ClassA

end

class Class= B

end

then we have a th= ird one, which has a method that references the first class:
class Evaluator
   
  &nb= sp;def evaluate
       return ClassA
<= div>   end

end

What I'd like to do is to be able to redefine what ClassA is for a give= n instance of Evaluator, like so:

ev =3D Evaluat= or.new
<redefine ClassA to ClassB in some way, for ev only&g= t;
ev.evaluate #ClassB

I found out how= to do this, but only class-wide:

ev =3D Evaluat= or.new
ev.evaluate #ClassA
class Evaluator
=   ClassA =3D ClassB
end
ev.evaluate #ClassB

Ideas?

Andrea
 
--
 
http://usingim= ho.wordpress.com
http://github.com/bolthar
=0A= =0A --_=__=_XaM3_.1344186742.2A.164376.42.1475.52.42.007.104103821--