O'Reilly - Ruby Pocket Reference.pdf

(3641 KB) Pobierz
1546608 UNPDF
1546608.006.png
Ruby
Pocket Reference
Michael Fitzgerald
Beijing Cambridge Farnham Köln Paris Sebastopol Taipei Tokyo
1546608.007.png 1546608.008.png 1546608.009.png
Ruby Pocket Reference
by Michael Fitzgerald
Copyright © 2007 Michael Fitzgerald. All rights reserved.
Printed in Canada.
Published by O’Reilly Media, Inc., 1005 Gravenstein Highway North,
Sebastopol, CA 95472.
O’Reilly books may be purchased for educational, business, or sales
promotional use. Online editions are also available for most titles
( safari.oreilly.com ). For more information, contact our corporate/
institutional sales department: (800) 998-9938 or corporate@oreilly.com .
Editor: Simon St.Laurent
Production Editor:
Rachel Monaghan
Proofreader: Rachel Monaghan
Indexer: Ellen Troutman Zaig
Cover Designer: Karen Montgomery
Interior Designer: David Futato
Illustrators: Robert Romano and
Jessamyn Read
Printing History:
July 2007:
First Edition.
Nutshell Handbook, the Nutshell Handbook logo, and the O’Reilly logo are
registered trademarks of O’Reilly Media, Inc. The Pocket Reference series
designations, Ruby Pocket Reference , the image of a giraffe, and related trade
dress are trademarks of O’Reilly Media, Inc.
Many of the designations used by manufacturers and sellers to distinguish
their products are claimed as trademarks. Where those designations appear
in this book, and O’Reilly Media, Inc. was aware of a trademark claim, the
designations have been printed in caps or initial caps.
While every precaution has been taken in the preparation of this book, the
publisher and author assume no responsibility for errors or omissions, or for
damages resulting from the use of the information contained herein.
ISBN-10: 0-596-51481-6
ISBN-13: 978-0-596-51481-5
[TM]
1546608.001.png
Contents
Running Ruby
2
Running the Ruby Interpreter
3
Using a Shebang Line on Unix/Linux
5
Associating File Types on Windows
5
Reserved Words
7
Operators
9
Comments
10
Numbers
11
Variables
11
Local Variables
12
Instance Variables
12
Class Variables
13
Global Variables
13
Constants
13
Parallel Assignment of Variables
13
Symbols
14
Predefined Variables
14
Pseudovariables
17
Global Constants
18
iii
1546608.002.png 1546608.003.png 1546608.004.png
Ranges
19
Methods
19
Parentheses
20
Return Values
20
Method Name Conventions
21
Default Arguments
22
Variable Arguments
22
Aliasing Methods
23
Blocks
23
Procs
25
Conditional Statements
27
The if Statement
27
The unless Statement
29
The while Statement
30
The until Statement
31
The case Statement
32
The for Loop
33
The Ternary Operator
34
Executing Code Before or After a Program
34
Classes
34
Instance Variables
36
Accessors
38
Class Variables
39
Class Methods
40
Singletons
40
Inheritance
42
Public, Private, or Protected
42
Modules and Mixins
44
iv
|
Contents
1546608.005.png
Zgłoś jeśli naruszono regulamin