<html> <head> <title>Ruby FAQ</title> </head> <body> Previous <a href="rubyfaq-1.html">Next</a> Table of contents <hr> <h1 align="center">Ruby FAQ</h1> <p align="right">September 27, 1999</p> <p> <h2><a name="toc1">1.</a><a href="rubyfaq-1.html"> General questions </a></h2> <ul> <li><a href="rubyfaq-1.html#ss1.1">1.1 What is Ruby? </a></li> <li><a href="rubyfaq-1.html#ss1.2">1.2 What does Ruby stand for? </a></li> <li><a href="rubyfaq-1.html#ss1.3">1.3 Teach me the Ruby history. </a></li> <li><a href="rubyfaq-1.html#ss1.4">1.4 Where is it available? </a></li> <li><a href="rubyfaq-1.html#ss1.5">1.5 Where is the Home Page of Ruby? </a></li> <li><a href="rubyfaq-1.html#ss1.6">1.6 Is there a Ruby mailing list? </a></li> <li><a href="rubyfaq-1.html#ss1.7">1.7 How can I search past mails of the mailing list? </a></li> <li><a href="rubyfaq-1.html#ss1.8">1.8 What is the difference between rubyist and Ruby hacker? </a></li> <li><a href="rubyfaq-1.html#ss1.9">1.9 Which is authentic, Ruby or ruby? </a></li> <li><a href="rubyfaq-1.html#ss1.10">1.10 Is there a Ruby book? </a></li> <li><a href="rubyfaq-1.html#ss1.11">1.11 I cannot understand Ruby even after reading the manual. </a></li> </ul> <p> <h2><a name="toc2">2.</a><a href="rubyfaq-2.html"> Variables, constants and arguments </a></h2> <ul> <li><a href="rubyfaq-2.html#ss2.1">2.1 Does assignment to a variable or a constant generate a new copy of an object? </a></li> <li><a href="rubyfaq-2.html#ss2.2">2.2 What is the definition of the scope of a local variable? </a></li> <li><a href="rubyfaq-2.html#ss2.3">2.3 When does a local variable become accessible? </a></li> <li><a href="rubyfaq-2.html#ss2.4">2.4 What is the definition of the scope of a constant? </a></li> <li><a href="rubyfaq-2.html#ss2.5">2.5 How is the actual argument passed to the formal argument? </a></li> <li><a href="rubyfaq-2.html#ss2.6">2.6 Does assignment to the formal argument influence the actual argument? </a></li> <li><a href="rubyfaq-2.html#ss2.7">2.7 What happens if I send a message to the object pointed by the formal argument </a></li> <li><a href="rubyfaq-2.html#ss2.8">2.8 What is the <code>*</code> prepended to an argument? </a></li> <li><a href="rubyfaq-2.html#ss2.9">2.9 What is the <code>&</code> prepended to an argument? </a></li> <li><a href="rubyfaq-2.html#ss2.10">2.10 Can I define a default value for a formal argument? </a></li> <li><a href="rubyfaq-2.html#ss2.11">2.11 How to pass arguments to a block. </a></li> <li><a href="rubyfaq-2.html#ss2.12">2.12 An unexpected change happens to the content of variables or constants. </a></li> <li><a href="rubyfaq-2.html#ss2.13">2.13 Does the value of a constant ever change? </a></li> </ul> <p> <h2><a name="toc3">3.</a><a href="rubyfaq-3.html"> Iterators </a></h2> <ul> <li><a href="rubyfaq-3.html#ss3.1">3.1 What is an iterator? </a></li> <li><a href="rubyfaq-3.html#ss3.2">3.2 How can I pass a block to an iterator? </a></li> <li><a href="rubyfaq-3.html#ss3.3">3.3 How is a block used in an iterator? </a></li> <li><a href="rubyfaq-3.html#ss3.4">3.4 What does <code>Proc.new</code> without a block do? </a></li> </ul> <p> <h2><a name="toc4">4.</a><a href="rubyfaq-4.html"> Syntax </a></h2> <ul> <li><a href="rubyfaq-4.html#ss4.1">4.1 What does <code>:exit</code> mean? </a></li> <li><a href="rubyfaq-4.html#ss4.2">4.2 How can I access the value of a symbol? </a></li> <li><a href="rubyfaq-4.html#ss4.3">4.3 Is <code>loop</code> a control structure? </a></li> <li><a href="rubyfaq-4.html#ss4.4">4.4 <code>a +b</code> gives an error. </a></li> <li><a href="rubyfaq-4.html#ss4.5">4.5 <code>s = "x"; puts s *10</code> gives an error. </a></li> <li><a href="rubyfaq-4.html#ss4.6">4.6 Nothing appears with <code>p {}</code>. </a></li> <li><a href="rubyfaq-4.html#ss4.7">4.7 After <code>def pos= (val) print @pos,"\n"; @pos = val end</code>, I cannot use the method <code>pos = 1</code>. </a></li> <li><a href="rubyfaq-4.html#ss4.8">4.8 What is the difference between <code>'\1'</code> and <code>'\\1'</code>? </a></li> <li><a href="rubyfaq-4.html#ss4.9">4.9 <code>p true or true and false</code> prints <code>true</code>, while <code>a=true if true or true and false</code> does not assign <code>true</code> to <code>a</code>. </a></li> <li><a href="rubyfaq-4.html#ss4.10">4.10 <code>p(nil || "")</code> returns "", while <code>p(nil or "")</code> gives parse error. </a></li> </ul> <p> <h2><a name="toc5">5.</a><a href="rubyfaq-5.html"> Methods </a></h2> <ul> <li><a href="rubyfaq-5.html#ss5.1">5.1 How is the method searched when a messeage is sent to an object? </a></li> <li><a href="rubyfaq-5.html#ss5.2">5.2 Are <code>+</code> and <code>-</code> operators? </a></li> <li><a href="rubyfaq-5.html#ss5.3">5.3 Are there any functions? </a></li> <li><a href="rubyfaq-5.html#ss5.4">5.4 Can I access an object instance variable? </a></li> <li><a href="rubyfaq-5.html#ss5.5">5.5 I cannot figure out the difference between <code>private</code> and <code>protected</code>. </a></li> <li><a href="rubyfaq-5.html#ss5.6">5.6 I want to make an instance variable public. </a></li> <li><a href="rubyfaq-5.html#ss5.7">5.7 How can I change the visibility of a method? </a></li> <li><a href="rubyfaq-5.html#ss5.8">5.8 Can I use an idenfier beginning with a capital letter for a method name? </a></li> <li><a href="rubyfaq-5.html#ss5.9">5.9 <code>super</code> yields an <code>ArgumentError</code>. </a></li> <li><a href="rubyfaq-5.html#ss5.10">5.10 How can I call the same name method of two levels upper? </a></li> <li><a href="rubyfaq-5.html#ss5.11">5.11 How can I invoke the original built-in method after redfining it? </a></li> <li><a href="rubyfaq-5.html#ss5.12">5.12 What is a destructive method? </a></li> <li><a href="rubyfaq-5.html#ss5.13">5.13 When does an adverse effect occur using a method? </a></li> <li><a href="rubyfaq-5.html#ss5.14">5.14 Can I return multiple values from a method? </a></li> </ul> <p> <h2><a name="toc6">6.</a><a href="rubyfaq-6.html"> Classes and modules </a></h2> <ul> <li><a href="rubyfaq-6.html#ss6.1">6.1 Can a class definition be repeated? </a></li> <li><a href="rubyfaq-6.html#ss6.2">6.2 Is there a class variable? </a></li> <li><a href="rubyfaq-6.html#ss6.3">6.3 What is a class instance variable? </a></li> <li><a href="rubyfaq-6.html#ss6.4">6.4 What is a singleton method? </a></li> <li><a href="rubyfaq-6.html#ss6.5">6.5 Is there a class method? </a></li> <li><a href="rubyfaq-6.html#ss6.6">6.6 What is a singleton class? </a></li> <li><a href="rubyfaq-6.html#ss6.7">6.7 What is a module function? </a></li> <li><a href="rubyfaq-6.html#ss6.8">6.8 What is the difference between a class and a module? </a></li> <li><a href="rubyfaq-6.html#ss6.9">6.9 Does a module generate a subclass? </a></li> <li><a href="rubyfaq-6.html#ss6.10">6.10 What is the difference between defining a class method in the class definition and directly at the toplevel? </a></li> <li><a href="rubyfaq-6.html#ss6.11">6.11 What is the difference between <code>load</code> and <code>require</code>? </a></li> <li><a href="rubyfaq-6.html#ss6.12">6.12 What is the difference between <code>include</code> and <code>extend</code>? </a></li> <li><a href="rubyfaq-6.html#ss6.13">6.13 What does <code>self</code> mean? </a></li> </ul> <p> <h2><a name="toc7">7.</a><a href="rubyfaq-7.html"> Builtin libraries </a></h2> <ul> <li><a href="rubyfaq-7.html#ss7.1">7.1 What is the return value of <code>instance_methods(nil)</code>? </a></li> <li><a href="rubyfaq-7.html#ss7.2">7.2 Why does <code>rand</code> generate the same random number sequence? </a></li> <li><a href="rubyfaq-7.html#ss7.3">7.3 How can I choose 5 different numbers between 0 and 51 randomly? </a></li> <li><a href="rubyfaq-7.html#ss7.4">7.4 As <code>Fixnum</code>, <code>true</code>, <code>nil</code>, and <code>false</code> are implemented as immediate values, what is the difference between an immediate value and a reference? </a></li> <li><a href="rubyfaq-7.html#ss7.5">7.5 What is the difference between <code>nil</code> and <code>false</code>? </a></li> <li><a href="rubyfaq-7.html#ss7.6">7.6 I read a file and changed the content, but the file does not change. </a></li> <li><a href="rubyfaq-7.html#ss7.7">7.7 How can I read a file and replace it with new one? </a></li> <li><a href="rubyfaq-7.html#ss7.8">7.8 I wrote a file and copied the file, but the tail of the copied file is truncated. </a></li> <li><a href="rubyfaq-7.html#ss7.9">7.9 How can I use <code>less</code> to display strings? </a></li> <li><a href="rubyfaq-7.html#ss7.10">7.10 What occurs to a <code>File</code> object which has no reference? </a></li> <li><a href="rubyfaq-7.html#ss7.11">7.11 I feel uneasy if I don't close a file. </a></li> <li><a href="rubyfaq-7.html#ss7.12">7.12 How can I sort files by their modified time? </a></li> <li><a href="rubyfaq-7.html#ss7.13">7.13 How can I count word frequency in a file? </a></li> <li><a href="rubyfaq-7.html#ss7.14">7.14 Null string ("") returns <code>true</code> in a condition expression. </a></li> <li><a href="rubyfaq-7.html#ss7.15">7.15 How can I sort strings in alphabetical order? </a></li> <li><a href="rubyfaq-7.html#ss7.16">7.16 What does <code>"abcd"[0]</code> return? </a></li> <li><a href="rubyfaq-7.html#ss7.17">7.17 How can I expand tabs to spaces? </a></li> <li><a href="rubyfaq-7.html#ss7.18">7.18 How can I escape a backslash? </a></li> <li><a href="rubyfaq-7.html#ss7.19">7.19 What is the difference between <code>sub</code> and <code>sub!</code>? </a></li> <li><a href="rubyfaq-7.html#ss7.20">7.20 Where does \Z match? </a></li> <li><a href="rubyfaq-7.html#ss7.21">7.21 What is the difference between Range constructors <code>..</code> and <code>...</code>? </a></li> <li><a href="rubyfaq-7.html#ss7.22">7.22 Is there a function pointer? </a></li> <li><a href="rubyfaq-7.html#ss7.23">7.23 What is the difference between <code>thread</code> and <code>fork</code>? </a></li> <li><a href="rubyfaq-7.html#ss7.24">7.24 How can I use Marshal? </a></li> <li><a href="rubyfaq-7.html#ss7.25">7.25 Is there an exception handling? </a></li> <li><a href="rubyfaq-7.html#ss7.26">7.26 How can I use <code>trap</code>? </a></li> </ul> <p> <h2><a name="toc8">8.</a><a href="rubyfaq-8.html"> Extension library </a></h2> <ul> <li><a href="rubyfaq-8.html#ss8.1">8.1 How can I use Ruby interactively? </a></li> <li><a href="rubyfaq-8.html#ss8.2">8.2 Is there a debugger for Ruby? </a></li> <li><a href="rubyfaq-8.html#ss8.3">8.3 How can I use a library written in C from Ruby? </a></li> <li><a href="rubyfaq-8.html#ss8.4">8.4 Can I use Tcl/Tk interface in Ruby? </a></li> <li><a href="rubyfaq-8.html#ss8.5">8.5 Tk won't work. </a></li> <li><a href="rubyfaq-8.html#ss8.6">8.6 Can I use <code>gtk+</code> or <code>xforms</code> interface in Ruby? </a></li> <li><a href="rubyfaq-8.html#ss8.7">8.7 How can I calculate dates? </a></li> </ul> <p> <h2><a name="toc9">9.</a><a href="rubyfaq-9.html"> Undocumented Features </a></h2> <ul> <li><a href="rubyfaq-9.html#ss9.1">9.1 What does <code>a ? b : c</code> mean? </a></li> <li><a href="rubyfaq-9.html#ss9.2">9.2 How can I count the number of lines in a file? </a></li> <li><a href="rubyfaq-9.html#ss9.3">9.3 What do <code>begin</code> and <code>end</code> of MatchingData return? </a></li> </ul> <p> Originally written by Shugo Maeda <code><a href="mailto:shugo@netlab.co.jp"> shugo@netlab.co.jp </a></code> <br> Transformed to SGML by Ozawa Sakuro <code><a href="mailto:crouton@duelists.org"> crouton@duelists.org</a></code> <br> Translated into English by gotoken <code><a href="mailto:gotoken@math.sci.hokudai.ac.jp"> gotoken@math.sci.hokudai.ac.jp</a></code> <br> Revised by Akira Endo <code><a href="mailto:akendo@t3.rim.or.jp"> akendo@t3.rim.or.jp</a></code> <br> since June 7, 1999 (original Sep 18, 1997) <br> Transformed to private XML on June 28, 1999, parsed with xmlparser by Yoshida Masato<code><a href="mailto:yoshidam@inse.co.jp"> yoshidam@inse.co.jp</a></code>, <code><a href="yoshidam@yoshidam.net"> yoshidam@yoshidam.net</a></code>. </p> <hr>Previous <a href="rubyfaq-1.html">Next</a> Table of contents </body> </html>