This is a multi-part message in MIME format.

------extPart_000_0019_01C0D3FB.F9799240
Content-Type: text/plain;
	charsetso-8859-1"
Content-Transfer-Encoding: quoted-printable

Hi,

I have done OO Perl for a while and started Ruby recently. I have had fun but run into some fundamental question and can't find info regarding the scope of base class instance variable in David & Andrew's book.

The following code
#-------------------------------------------------------------
class Base
  def initialize()
    @s = "Base::init@#{self.class}"
    @v = 1
    puts "<#{@s.id}>=#{@s}, <#{@v.id}>=#{@v}"
  end
  def dump_base
    puts "<#{@s.id}>=#{@s}, <#{@v.id}>=#{@v}"
  end
end

class Ext < Base
  def initialize()
    super
    @s = "Ext::init@#{self.class}"
    @v = 2
  end
  def dump_ext 
    puts "<#{@s.id}>=#{@s}, <#{@v.id}>=#{@v}"
  end
end

$y = Ext.new()
$y.dump_ext()
$y.dump_base()
#------------------------------------------------------------

gives me the following result which is kind of unexpected

<84004400>=Base::init@Ext, <3>=1
<84004412>=Ext::init@Ext, <5>=2
<84004412>=Ext::init@Ext, <5>=2

Is this by Ruby's design? If that is the case,  how can I prevent myself from overwriting the variables if I use someone else's library without peeking into their source? Your answer is much appreciated.
                                    /\    /\
Chochain Lee      --------------------QQQ-^--QQQ-------------------------


------extPart_000_0019_01C0D3FB.F9799240
Content-Type: text/html;
	charsetso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=iso-8859-1">
<META content="MSHTML 5.50.4522.1800" name=GENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=#ffffff>
<DIV><FONT face=Arial>Hi,</FONT></DIV>
<DIV><FONT face=Arial></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial>I have done OO Perl&nbsp;for a while&nbsp;and started Ruby 
recently. I have had&nbsp;fun but run into some fundamental question and can't 
find info regarding the scope of base class instance variable&nbsp;in&nbsp;David 
&amp; Andrew's book.</FONT></DIV>
<DIV><FONT face=Arial></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial>The following code</FONT></DIV>
<DIV><FONT 
face=Courier>#-------------------------------------------------------------</FONT></DIV>
<DIV><FONT face=Courier>class Base<BR>&nbsp; def 
initialize()<BR>&nbsp;&nbsp;&nbsp;&nbsp;@s = 
"Base::init@#{self.class}"<BR>&nbsp;&nbsp;&nbsp;&nbsp;@v = 
1<BR>&nbsp;&nbsp;&nbsp;&nbsp;puts "&lt;</FONT><A 
href="mailto:#{@s.id}>=#{@s"><FONT 
face=Courier>#{@s.id}&gt;=#{@s</FONT></A><FONT face=Courier>}, &lt;</FONT><A 
href="mailto:#{@v.id}>=#{@v"><FONT 
face=Courier>#{@v.id}&gt;=#{@v</FONT></A><FONT face=Courier>}"<BR>&nbsp; 
end<BR>&nbsp; def dump_base<BR>&nbsp;&nbsp;&nbsp;&nbsp;puts "&lt;</FONT><A 
href="mailto:#{@s.id}>=#{@s"><FONT 
face=Courier>#{@s.id}&gt;=#{@s</FONT></A><FONT face=Courier>}, &lt;</FONT><A 
href="mailto:#{@v.id}>=#{@v"><FONT 
face=Courier>#{@v.id}&gt;=#{@v</FONT></A><FONT face=Courier>}"<BR>&nbsp; 
end<BR>end</FONT></DIV>
<DIV><FONT face=Courier></FONT>&nbsp;</DIV>
<DIV><FONT face=Courier>class Ext &lt; Base<BR>&nbsp; def 
initialize()<BR>&nbsp;&nbsp;&nbsp; super<BR>&nbsp;&nbsp;&nbsp;&nbsp;@s = 
"Ext::init@#{self.class}"<BR>&nbsp;&nbsp;&nbsp;&nbsp;@v = 2<BR>&nbsp; 
end<BR>&nbsp; def dump_ext&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;puts "&lt;</FONT><A 
href="mailto:#{@s.id}>=#{@s"><FONT 
face=Courier>#{@s.id}&gt;=#{@s</FONT></A><FONT face=Courier>}, &lt;</FONT><A 
href="mailto:#{@v.id}>=#{@v"><FONT 
face=Courier>#{@v.id}&gt;=#{@v</FONT></A><FONT face=Courier>}"<BR>&nbsp; 
end<BR>end</FONT></DIV>
<DIV><FONT face=Courier></FONT>&nbsp;</DIV>
<DIV><FONT face=Courier>$y = 
Ext.new()<BR>$y.dump_ext()<BR>$y.dump_base()<BR>#------------------------------------------------------------</FONT></DIV>
<DIV><FONT face=Courier></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial>gives me the following result which is kind of 
unexpected</FONT></DIV>
<DIV><FONT face=Courier></FONT>&nbsp;</DIV>
<DIV><FONT face=Courier>&lt;84004400&gt;=Base::init@Ext, 
&lt;3&gt;=1<BR>&lt;84004412&gt;=Ext::init@Ext, 
&lt;5&gt;=2<BR>&lt;84004412&gt;=Ext::init@Ext, &lt;5&gt;=2<BR></FONT></DIV>
<DIV><FONT face=Arial>Is this by Ruby's design? If that is the case,&nbsp; how 
can I prevent myself from overwriting&nbsp;the variables&nbsp;if I use someone 
else's library without peeking into their source? Your answer is much 
appreciated.</FONT></DIV>
<DIV><FONT 
face=Courier>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
/\&nbsp;&nbsp;&nbsp; /\<BR>Chochain Lee&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
--------------------QQQ-^--QQQ-------------------------<BR></FONT></DIV></BODY></HTML>

------extPart_000_0019_01C0D3FB.F9799240--