ruby学习笔记系列(1)



Notation Conventions
Throughout this book, we use the following typographic notations.
Literal code examples are shown using a typewriter-like font.
class SampleCode
def run
#...
end
end
Within the text, Fred#do_something is a reference to an instance method (in this case
do_something) of class Fred, Fred.new2 is a class method, and Fred::EOF is a class
constant. The decision to use a hash character to indicate instance methods was a tough
one: it isn’t valid Ruby syntax, but we thought that it was important to differentiate
between the instance and class methods of a particular class. When you see us write
File.read, you know we’re talking about the class method read. When instead we
write File#read, we’re referring to the instance method read.

2

install ruby(cvs install)

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 https://www.cvshome.org) as their revision control
system. You can check files out as an anonymous user from their
archive by executing the following CVS commands:
% cvs z4
d
:pserver:[email protected].
org:/src←֓
login
(Logging in to [email protected].
org)
CVS password: ENTER
% cvs z4
d
:pserver:[email protected].
org:/src←֓
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.
This command will check out the head of the development tree. If you
want the Ruby 1.8 branch, add r
ruby_1_8 after the word checkout
in the second command.
If you use the CVSup mirroring utility (conveniently available from
http://www.cvsup.org), you can find Ruby supfiles on the rubylang
site at http://cvs.rubylang.
org/cvsup/.
Interactive Ruby
One way to run Ruby interactively is simply to type ruby at the shell prompt. Here
we typed in the single puts expression and an end-of-file character (which is Ctrl+D
on our system). This process works, but it’s painful if you make a typo, and you can’t
really see what’s going on as you type.
% ruby
puts "Hello, world!"
^D
Hello, world!
For most folks, irb—Interactive Ruby—is the tool of choice for executing Ruby interactively.
irb is a Ruby Shell, complete with command-line history, line-editing capabilities,
and job control. (In fact, it has its own chapter beginning on page 174.) You run
irb from the command line. Once it starts, just type in Ruby code. It will show you the
value of each expression as it evaluates it.
Prepared exclusively for Yeganefar

3
  Control Structures

if count > 10
puts "Try again"
elsif tries == 3
puts "You lose"
else
puts "Enter a number"
end


while weight < 100 and num_pallets <= 30
pallet = next_pallet()
weight += pallet.weight
num_pallets += 1
end

你可能感兴趣的:(Ruby,cvs)