|
|||
Previous < |
Contents ^
|
Next >
|
Sidebar: The Very Latest Ruby |
For those who just have to be on the very latest, hot-off-the-press and
untested cutting edge (as we were while writing this book),
you can get development versions straight from the developers'
working repository.
The Ruby developers use CVS (Concurrent Version System, freely
available from http://www.cvshome.com) as their revision control
system. You can check files out as an anonymous user from their
archive by executing the following CVS commands:
% cvs -d :pserver:anonymous@cvs.netlab.co.jp:/home/cvs
login
(Logging in to anonymous@cvs.netlab.co.jp)
CVS password: guest
% cvs -d :pserver:anonymous@cvs.netlab.co.jp:/home/cvs
checkout ruby
The complete source code tree, just as the developers last left it,
will now be copied to a ``ruby'' subdirectory on your machine,
updating your local source tree from a repository on the other side of
the world. Isn't it a great time to be alive?
|
README
, which
explains the installation procedure in detail. To summarize, you
build Ruby on POSIX-based systems using the same four commands you
use for most other open source applications:
./configure
, make
, make test
, and make
install
. You can build Ruby under other environments (including
Windows) by using a POSIX emulation environment such as
cygwin
[See http://sourceware.cygnus.com/cygwin for
details.] or by using native compilers---see ``ntsetup.bat
'' in
the distribution's win32
subdirectory as a starting point.
% ruby puts "Hello, world!" ^D Hello, world! |
puts
expression and
an end of file character (which is control-D on our system).
This process works, but it's sort of painful if you make
a typo, and you can't really see what's going on as you type.
In the sample
directory in the Ruby distribution you'll find
a script named ``eval.rb
''. It goes one step better by showing us
the value of each expression as it is entered:
% cd sample % ruby eval.rb ruby> a = "Hello, world!" "Hello, world!" ruby> puts a Hello, world! nil ruby> ^D % |
puts
, and then the return value
from puts
(which is nil
).
That's all fine and well, except that multiline expressions do not
work, and you can't edit the line you're on, or go back and use
previous lines (as you might with command history in a shell).
For the next step up from eval.rb
, we have irb
---Interactive
Ruby. irb
is a Ruby Shell, complete with command-line history,
line editing capabilities, and job control. It is quite configurable
and has many options, so much so that it has its own appendix beginning
on page 517. We recommend that you get familiar with irb
so you can try some of our examples interactively.
% ruby myprog.rb |
#!/usr/bin/env ruby
, which will search your path for ruby
and then execute it.]
#!/usr/local/bin/ruby -w puts "Hello, World!" |
chmod +x myprog.rb
), Unix lets you run the file as a
program:
% ./myprog.rb Hello, World! |
Date
module. Guy Decoux and
Clemens Hintze patiently answered our questions about
writing Ruby extensions, and Masaki Suketa helped us
understand the WinOLE
module.
Although much of the original Ruby documentation is in Japanese, there
is a growing body of English translations, mostly undertaken by
Japanese developers whose skills with English never cease to amaze
us. Although there are too many individual contributions to this
effort to name each author, we would like to single out
Goto Kentaro, who has produced a large volume of
high-quality documentation and placed it online.
Finally, we have to thank Yukihiro ``Matz'' Matsumoto, the creator of
Ruby. We've lost count of the number of questions we've asked of him,
and the number of patient and detailed answers he's sent back. As well
as creating a truly wonderful language, Matz has fostered a
wonderfully supportive and open culture in which that language can
prosper.
Thank you all. Domo arigato gozaimasu.
Dave Thomas and Andy Hunt
class SampleCode def run #... end end |
Fred#doIt
is a reference to an instance method
(doIt
) of class Fred
, while Fred.new
[In
some other Ruby documentation, you may see class methods written as
Fred::new
. This is perfectly valid Ruby syntax; we just happen
to feel that Fred.new
is less distracting to read.] is a class
method, and Fred::EOF
is a class constant.
The book contains many snippets of Ruby code. Where possible, we've
tried to show what happens when they run. In simple cases, we show the
value of expressions on the same line as the expression. For example:
a = 1
|
||
b = 2
|
||
a + b
|
» |
3
|
a = 1
|
» |
1
|
b = 2
|
» |
2
|
a + b
|
» |
3
|
3.times { puts "Hello!" } |
Hello! Hello! Hello! |
ruby [ flags ]* [ progname ] [ arguments ]+ |
Previous < |
Contents ^
|
Next >
|