S
Steve Tuckner
This is a multi-part message in MIME format.
------=_NextPart_000_0C14_01C3529D.6058A0B0
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
Anyone have an idea of why the following code doesn't work?
class A
class << self
def inherited(subclass)
name = subclass.my_name
puts "the inheriting classes name is '#{name}'"
end
end
end
class B < A
class << self
def my_name
"the B class"
end
end
end
It fails with:
t.rb:4:in `inherited': undefined method `my_name' for B:Class
(NameError)
from t.rb:10
Steve Tuckner
------=_NextPart_000_0C14_01C3529D.6058A0B0
Content-Type: text/html;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META content=3D"MSHTML 6.00.2600.0" name=3DGENERATOR></HEAD>
<BODY>
<DIV><FONT face=3DArial size=3D2><SPAN =
class=3D321350816-25072003>Anyone have an idea=20
of why the following code doesn't work?</SPAN></FONT></DIV>
<DIV><FONT face=3DArial size=3D2><SPAN=20
class=3D321350816-25072003></SPAN></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2><SPAN class=3D321350816-25072003>class =
A<BR> class << self<BR> def=20
inherited(subclass)<BR> name =3D=20
subclass.my_name<BR> puts "the inheriting =
classes name=20
is =
'#{name}'"<BR> end<BR> end<BR>end</SPAN></FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2><SPAN class=3D321350816-25072003>class =
B <=20
A<BR> class << self<BR> def=20
my_name<BR> "the B =
class"<BR> =20
end<BR> end<BR>end<BR></SPAN></FONT></DIV>
<DIV><FONT face=3DArial size=3D2><SPAN class=3D321350816-25072003>It =
fails with:=20
</SPAN></FONT></DIV>
<DIV><FONT face=3DArial size=3D2><SPAN=20
class=3D321350816-25072003></SPAN></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2><SPAN =
class=3D321350816-25072003>t.rb:4:in=20
`inherited': undefined method `my_name' for B:Class=20
(NameError)<BR> from=20
t.rb:10</DIV></SPAN></FONT>
<P><FONT face=3DArial size=3D2>Steve Tuckner</FONT> <BR></P>
<DIV> </DIV></BODY></HTML>
------=_NextPart_000_0C14_01C3529D.6058A0B0--
------=_NextPart_000_0C14_01C3529D.6058A0B0
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
Anyone have an idea of why the following code doesn't work?
class A
class << self
def inherited(subclass)
name = subclass.my_name
puts "the inheriting classes name is '#{name}'"
end
end
end
class B < A
class << self
def my_name
"the B class"
end
end
end
It fails with:
t.rb:4:in `inherited': undefined method `my_name' for B:Class
(NameError)
from t.rb:10
Steve Tuckner
------=_NextPart_000_0C14_01C3529D.6058A0B0
Content-Type: text/html;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META content=3D"MSHTML 6.00.2600.0" name=3DGENERATOR></HEAD>
<BODY>
<DIV><FONT face=3DArial size=3D2><SPAN =
class=3D321350816-25072003>Anyone have an idea=20
of why the following code doesn't work?</SPAN></FONT></DIV>
<DIV><FONT face=3DArial size=3D2><SPAN=20
class=3D321350816-25072003></SPAN></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2><SPAN class=3D321350816-25072003>class =
A<BR> class << self<BR> def=20
inherited(subclass)<BR> name =3D=20
subclass.my_name<BR> puts "the inheriting =
classes name=20
is =
'#{name}'"<BR> end<BR> end<BR>end</SPAN></FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2><SPAN class=3D321350816-25072003>class =
B <=20
A<BR> class << self<BR> def=20
my_name<BR> "the B =
class"<BR> =20
end<BR> end<BR>end<BR></SPAN></FONT></DIV>
<DIV><FONT face=3DArial size=3D2><SPAN class=3D321350816-25072003>It =
fails with:=20
</SPAN></FONT></DIV>
<DIV><FONT face=3DArial size=3D2><SPAN=20
class=3D321350816-25072003></SPAN></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2><SPAN =
class=3D321350816-25072003>t.rb:4:in=20
`inherited': undefined method `my_name' for B:Class=20
(NameError)<BR> from=20
t.rb:10</DIV></SPAN></FONT>
<P><FONT face=3DArial size=3D2>Steve Tuckner</FONT> <BR></P>
<DIV> </DIV></BODY></HTML>
------=_NextPart_000_0C14_01C3529D.6058A0B0--