📄 3.4.htm
字号:
<TABLE cellSpacing=0 cellPadding=5 width="100%" border=0>
<TBODY>
<TR>
<TD vAlign=top width=67 rowSpan=3><IMG
src="3.4.files/ruby_xs.gif" width=67 border=0></TD>
<TD class=v2 vAlign=top><A class=v1
href="http://proquest.safaribooksonline.com/JVXSL.asp?x=1&mode=section&sortKey=title&sortOrder=asc&view=&xmlid=0-59600-214-9&open=false&catid=&s=1&b=1&f=1&t=0&c=1&u=1&srchText=">Ruby
in a Nutshell</A><BR>By Yukihiro Matsumoto<BR></TD></TR>
<TR>
<TD class=v2> </TD></TR>
<TR>
<TD class=t1 vAlign=bottom>Chapter 3. Built-in Library
Reference</TD></TR></TBODY></TABLE>
<HR SIZE=1>
<BR>
<TABLE cellSpacing=0 cellPadding=0 width="100%" border=0>
<TBODY>
<TR>
<TD vAlign=top><A name=ruby-CHP-3-SECT-4></A>
<H3 class=docSection1Title>3.4 Built-in Library</H3><A
name=IXT-3-127391></A>
<P class=docText>Ruby's built-in library provides you with a
rich set of classes that form the foundation for your Ruby
programs. There are classes for manipulating text
(<TT>String</TT>), operating system services and abstractions
(<TT>IO</TT>, <TT>File</TT>, <TT>Process</TT>, etc.), numbers
(<TT>Integer</TT>, <TT>Fixnum</TT>, etc.), and so on. </P>
<P class=docText>Using these basic building blocks, you can
build powerful Ruby programs. But wait, in the next chapter, I
lay out the Standard Library, which extends Ruby's
flexibility. </P><A name=ruby-CHP-3-SECT-4.1></A>
<H4 class=docSection2Title>3.4.1 Objects</H4><A
name=IXT-3-127392></A><A name=IXT-3-127393></A>
<P class=docText>Ruby couldn't lay claim to being an
"object-oriented scripting language" without providing
fundamental tools for OOP. This basic support is provided
through the <TT>Object</TT> class. </P><A
name=ch03-3-fm2xml></A><A name=IXT-3-127394></A><A
name=IXT-3-127395></A><A name=IXT-3-127396></A><A
name=IXT-3-127397></A>
<TABLE cellPadding=5 width=515 border=0>
<TBODY>
<TR>
<TD align=left><B><I>Object</I></B></TD>
<TD align=right><I>Superclass of all classes
</I></TD></TR></TBODY></TABLE>
<HR align=left width=515 color=black noShade SIZE=3>
<TABLE cellPadding=5 width=515 border=0>
<TBODY>
<TR>
<TD align=left></TD>
<TD align=right></TD></TR></TBODY></TABLE>
<P class=docText><TT>Object</TT><A name=IXT-3-127394></A> is
the parent class of all other classes. When a method is
defined at the top level, it becomes a private method of this
class, making it executable by all classes as if it were a
function in other languages. </P><A name=ch03-4-fm2xml></A>
<H4 class=docRefsectTitle>Included Modules</H4>
<P class=docText><TT>Kernel</TT></P><A name=ch03-5-fm2xml></A>
<H4 class=docRefsectTitle>Private Instance Methods</H4><A
name=IXT-3-127395></A><A name=IXT-3-127396></A><A
name=IXT-3-127397></A>
<DL class=docList><A name=IXT-3-127395></A><A
name=IXT-3-127396></A>
<DT><SPAN class=docPubcolor><SPAN class=docPubcolor><SPAN
class=docMonofont>initialize</SPAN></SPAN></SPAN>
<DD>
<P class=docList><A name=IXT-3-127397></A>Initializes an
object. Any block and arguments associated with the
<TT>new</TT> method are passed directly to
<TT>initialize</TT>. It's assumed that this method will be
redefined by subclasses for object initialization.
</P></DD></DL><A name=ch03-6-fm2xml></A><A
name=ruby-IDXTERM-653></A><A name=IXT-3-127398></A><A
name=IXT-3-127399></A><A name=IXT-3-127400></A><A
name=IXT-3-127401></A><A name=IXT-3-127402></A><A
name=IXT-3-127403></A><A name=IXT-3-127404></A><A
name=IXT-3-127405></A><A name=IXT-3-127406></A><A
name=IXT-3-127407></A><A name=IXT-3-127408></A><A
name=IXT-3-127409></A><A name=IXT-3-127410></A><A
name=IXT-3-127411></A><A name=IXT-3-127412></A><A
name=IXT-3-127413></A><A name=IXT-3-127414></A><A
name=IXT-3-127415></A><A name=IXT-3-127416></A><A
name=IXT-3-127417></A><A name=IXT-3-127418></A><A
name=IXT-3-127419></A><A name=IXT-3-127420></A><A
name=IXT-3-127421></A><A name=IXT-3-127422></A><A
name=IXT-3-127423></A><A name=IXT-3-127424></A><A
name=IXT-3-127425></A><A name=IXT-3-127426></A><A
name=IXT-3-127427></A><A name=IXT-3-127428></A><A
name=IXT-3-127429></A><A name=IXT-3-127430></A><A
name=IXT-3-127431></A><A name=IXT-3-127432></A><A
name=IXT-3-127433></A><A name=IXT-3-127434></A><A
name=IXT-3-127435></A><A name=IXT-3-127436></A><A
name=IXT-3-127437></A><A name=IXT-3-127438></A><A
name=IXT-3-127439></A>
<TABLE cellPadding=5 width=515 border=0>
<TBODY>
<TR>
<TD align=left><B><I>Kernel</I></B></TD>
<TD align=right><I>Module containing built-in functions
</I></TD></TR></TBODY></TABLE>
<HR align=left width=515 color=black noShade SIZE=3>
<TABLE cellPadding=5 width=515 border=0>
<TBODY>
<TR>
<TD align=left></TD>
<TD align=right></TD></TR></TBODY></TABLE>
<P class=docText><TT>Kernel</TT><A name=ruby-IDXTERM-653></A>
is the module in which Ruby's built-in functions are defined
as module functions. Since it's included in <TT>Object</TT>,
<TT>Kernel</TT> is indirectly included in all classes. </P><A
name=ch03-7-fm2xml></A>
<H4 class=docRefsectTitle>Private Instance Methods</H4>
<P class=docText><A name=IXT-3-127398></A>Function-like
methods are private methods of <TT>Kernel</TT>. Although the
following methods fall into the same category, they are more
similar to standard private instance methods than
function-like methods. </P><A name=IXT-3-127399></A>
<DL class=docList><A name=IXT-3-127399></A>
<DT><SPAN class=docPubcolor><SPAN class=docPubcolor><SPAN
class=docMonofont>remove_instance_variable(</SPAN></SPAN>
<TT><I>name</I></TT><SPAN class=docPubcolor><SPAN
class=docMonofont>)</SPAN></SPAN> </SPAN>
<DD>
<P class=docList>Removes instance variable specified by
<TT><I>name</I></TT>. </P></DD></DL><A name=ch03-8-fm2xml></A>
<H4 class=docRefsectTitle>Instance Methods</H4><A
name=IXT-3-127400></A><A name=IXT-3-127401></A><A
name=IXT-3-127402></A><A name=IXT-3-127403></A><A
name=IXT-3-127404></A><A name=IXT-3-127405></A><A
name=IXT-3-127406></A><A name=IXT-3-127407></A><A
name=IXT-3-127408></A><A name=IXT-3-127409></A><A
name=IXT-3-127410></A><A name=IXT-3-127411></A><A
name=IXT-3-127412></A><A name=IXT-3-127413></A><A
name=IXT-3-127414></A><A name=IXT-3-127415></A><A
name=IXT-3-127416></A><A name=IXT-3-127417></A><A
name=IXT-3-127418></A><A name=IXT-3-127419></A><A
name=IXT-3-127420></A><A name=IXT-3-127421></A><A
name=IXT-3-127422></A><A name=IXT-3-127423></A><A
name=IXT-3-127424></A><A name=IXT-3-127425></A><A
name=IXT-3-127426></A><A name=IXT-3-127427></A><A
name=IXT-3-127428></A><A name=IXT-3-127429></A><A
name=IXT-3-127430></A><A name=IXT-3-127431></A><A
name=IXT-3-127432></A><A name=IXT-3-127433></A><A
name=IXT-3-127434></A><A name=IXT-3-127435></A><A
name=IXT-3-127436></A><A name=IXT-3-127437></A><A
name=IXT-3-127438></A><A name=IXT-3-127439></A>
<DL class=docList>
<DT><SPAN class=docPubcolor><TT><I>o</I></TT> <SPAN
class=docPubcolor><SPAN class=docMonofont>==
other</SPAN></SPAN> </SPAN>
<DD>
<P class=docList>Determines if the values are equal.</P>
<DT><SPAN class=docPubcolor><TT><I>o</I></TT> <SPAN
class=docPubcolor><SPAN class=docMonofont>===
other</SPAN></SPAN> </SPAN>
<DD>
<P class=docList>Comparison operator used by <TT>case</TT>
statement (compares equality or confirms class membership).
</P>
<DT><SPAN class=docPubcolor><TT><I>o</I></TT> <SPAN
class=docPubcolor><SPAN class=docMonofont>=~
other</SPAN></SPAN> </SPAN>
<DD>
<P class=docList>Checks for pattern matches. The definition
in <TT>Kernel</TT> calls <TT>===</TT>. </P><A
name=IXT-3-127400></A>
<DT><SPAN class=docPubcolor><TT><I>o</I></TT><SPAN
class=docPubcolor><SPAN
class=docMonofont>.class</SPAN></SPAN> </SPAN>
<DD>
<P class=docList></P><A name=IXT-3-127401></A>
<DT><SPAN class=docPubcolor><TT><I>o</I></TT><SPAN
class=docPubcolor><SPAN
class=docMonofont>.type</SPAN></SPAN> </SPAN>
<DD>
<P class=docList>Returns the class of the object
<TT><I>o</I></TT>.</P><A name=IXT-3-127402></A>
<DT><SPAN class=docPubcolor><TT><I>o</I></TT><SPAN
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -