logo资料库

Ruby_Programming.pdf

第1页 / 共261页
第2页 / 共261页
第3页 / 共261页
第4页 / 共261页
第5页 / 共261页
第6页 / 共261页
第7页 / 共261页
第8页 / 共261页
资料共261页,剩余部分请下载后查看
1 Overview
1.1 Features
1.2 References
2 Installing Ruby
2.1 Operating systems
2.2 Building from Source
2.3 Compile options
2.4 Testing Installation
2.5 References
3 Ruby editors
4 Notation conventions
4.1 Command-line examples
5 Interactive Ruby
5.1 Running irb
5.2 Understanding irb output
6 Mailing List FAQ
7 Basic Ruby - Hello world
7.1 Hello world
7.2 Comments
7.3 Executable Ruby scripts
8 Basic Ruby - Strings
8.1 String literals
8.2 Single quotes
8.3 Double quotes
8.4 puts
8.5 print
8.6 See also
9 Basic Ruby - Alternate quotes
9.1 Alternate single quotes
9.2 Alternate double quotes
10 Basic Ruby - Here documents
10.1 Here documents
10.2 Indenting
10.3 Quoting rules
11 Basic Ruby - Introduction to objects
11.1 What is an object?
11.2 Variables and objects
11.3 Methods
11.4 Reassigning a variable
12 Basic Ruby - Ruby basics
13 Dealing with variables
14 Program flow
15 Writing functions
16 Blocks
17 Ruby is really, really object-oriented
18 Basic Ruby - Data types
18.1 Ruby Data Types
18.2 Constants
18.3 Symbols
18.4 Hashes
18.5 Arrays
18.6 Strings
18.7 Numbers (Integers and Floats)
18.8 Additional String Methods
19 Basic Ruby - Writing methods
19.1 Defining Methods
20 Basic Ruby - Classes and objects
20.1 Ruby Classes
20.2 Creating Instances of a Class
20.3 Creating Classes
20.4 Self
20.5 Class Methods
21 Basic Ruby - Exceptions
22 Syntax - Lexicology
22.1 Identifiers
22.2 Comments
22.3 Embedded Documentation
22.4 Reserved Words
22.5 Expressions
23 Syntax - Variables and Constants
23.1 Local Variables
23.2 Instance Variables
23.3 Class Variables
23.4 Global Variables
23.5 Constants
23.6 Pseudo Variables
23.7 Pre-defined Variables
23.8 Pre-defined Constants
23.9 Notes
24 Syntax - Literals
24.1 Numerics
24.2 Strings
24.3 Arrays
24.4 Hashes
24.5 Ranges
25 Syntax - Operators
25.1 Operators
25.2 Scope
25.3 Default scope
25.4 Local scope gotchas
25.5 Logical And
25.6 Logical Or
26 Syntax - Control Structures
26.1 Control Structures
27 Syntax - Method Calls
27.1 Method Calls
27.2 Method Definitions
27.3 Dynamic methods
27.4 Special methods
27.5 Conclusion
28 Syntax - Classes
28.1 Class Definition
28.2 Declaring Visibility
28.3 Inheritance
28.4 Mixing in Modules
28.5 Ruby Class Meta-Model
29 Syntax - Hooks
29.1 const_missing
30 References
31 Built-In Functions
32 Predefined Variables
33 Predefined Classes
33.1 Footnotes
34 Objects
35 Array
36 Class
37 Comparable
38 Encoding
39 Enumerable
39.1 Enumerable
40 Forms of Enumerator
40.1 1. As a proxy for “each”
40.2 2. As a source of values from a block
40.3 3. As an external iterator
41 Lazy evaluation
42 Methods which return Enumerators
43 More Enumerator readings
44 Exception
45 FalseClass
46 IO - Fiber
47 IO
47.1 Encoding
47.2 gets
47.3 recv
47.4 read
48 IO - File
49 File
49.1 File#chmod
49.2 File#grep
49.3 File.join
50 IO - File::Stat
51 File::Stat
52 IO - GC
53 GC
53.1 Tuning the GC
53.2 Conservative
53.3 Tunning Jruby's GC.
53.4 How to avoid performance penalty
54 IO - GC - Profiler
55 Marshal
56 Marshal
57 Method
58 Math
59 Module
60 Module - Class
61 NilClass
62 Numeric
63 Numeric - Integer
64 Numeric - Integer - Bignum
65 Numeric - Integer - Fixnum
66 Numeric - Float
67 Range
68 Regexp
69 Regexp Regular Expressions
69.1 oniguruma
69.2 Simplifying regexes
69.3 Helper websites
69.4 Alternative Regular Expression Libraries
70 RubyVM
70.1 RubyVM::InstructionSequence.disassemble
71 String
72 Struct
73 Struct
74 Struct - Struct::Tms
75 Symbol
76 Time
77 Thread
78 Thread
78.1 Thread local variables
78.2 Joining on multiple threads
78.3 Controlling Concurrency
79 TrueClass
80 Contributors
List of Figures
81 Licenses
81.1 GNU GENERAL PUBLIC LICENSE
81.2 GNU Free Documentation License
81.3 GNU Lesser General Public License
Ruby Programming Wikibooks.org
December 1, 2012 On the 28th of April 2012 the contents of the English as well as German Wikibooks and Wikipedia projects were licensed under Creative Commons Attribution-ShareAlike 3.0 Unported license. An URI to this license is given in the list of figures on page 249. If this document is a derived work from the contents of one of these projects and the content was still licensed by the project under this license at the time of derivation this document has to be licensed under the same, a similar or a compatible license, as stated in section 4b of the license. The list of contributors is included in chapter Contributors on page 243. The licenses GPL, LGPL and GFDL are included in chapter Licenses on page 253, since this book and/or parts of it may or may not be licensed under one or more of these licenses, and thus require inclusion of these licenses. The licenses of the figures are given in the list of figures on page 249. This PDF was generated by the LATEX typesetting software. The LATEX source code is included as an attachment (source.7z.txt) in this PDF file. To extract the source from the PDF file, we recommend the use of http://www.pdflabs.com/tools/pdftk-the-pdf-toolkit/ utility or clicking the paper clip attachment symbol on the lower left of your PDF Viewer, selecting Save Attachment. After extracting it from the PDF file you have to rename it to source.7z. To uncompress the resulting archive we recommend the use of http://www.7-zip.org/. The LATEX source itself was generated by a program written by Dirk HÃijnniger, which is freely available under an open source license from http://de.wikibooks.org/wiki/Benutzer:Dirk_Huenniger/wb2pdf. This distribution also contains a configured version of the pdflatex compiler with all necessary packages and fonts needed to compile the LATEX source included in this PDF file.
Contents . . . 2 5 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 Ruby editors . . 4 Notation conventions . . 6 Mailing List FAQ . 7 Basic Ruby - Hello world . . . . . . . . . 1.1 Features . . . . 1.2 References . . Installing Ruby . . . 2.1 Operating systems . 2.2 Building from Source . . 2.3 Compile options . . . 2.4 Testing Installation . 2.5 References . . . . . . . . . . . . . . . . . . . 4.1 Command-line examples . . . Interactive Ruby . . . . 5.1 Running irb . . . . 5.2 Understanding irb output . . . . . . . . . 7.1 Hello world . . 7.2 Comments . . . . 7.3 Executable Ruby scripts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 Basic Ruby - Introduction to objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11.1 What is an object? . . 11.2 Variables and objects . . 11.3 Methods . . 11.4 Reassigning a variable 12 Basic Ruby - Ruby basics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . puts print 8 Basic Ruby - Strings . 8.1 String literals 8.2 Single quotes . 8.3 Double quotes . . . 8.4 . 8.5 . 8.6 See also . . . . . . . . . 9 Basic Ruby - Alternate quotes 9.1 Alternate single quotes . 9.2 Alternate double quotes . 10 Basic Ruby - Here documents . . . . 10.1 Here documents . . 10.2 Indenting . 10.3 Quoting rules . . . . . . . . . . . . . . . . . . . . 3 3 6 7 7 10 10 10 11 13 15 15 17 17 18 19 21 21 22 22 27 27 27 28 29 29 30 31 31 32 33 33 34 35 37 37 37 38 39 41 III
Contents . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19.1 Defining Methods . 19 Basic Ruby - Writing methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 Dealing with variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14 Program flow . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15 Writing functions . 16 Blocks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17 Ruby is really, really object-oriented . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18 Basic Ruby - Data types . 18.1 Ruby Data Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18.2 Constants . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18.3 Symbols . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18.4 Hashes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18.5 Arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18.6 Strings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18.7 Numbers (Integers and Floats) . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18.8 Additional String Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20 Basic Ruby - Classes and objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20.1 Ruby Classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20.2 Creating Instances of a Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20.3 Creating Classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20.4 Self . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20.5 Class Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21 Basic Ruby - Exceptions 22 Syntax - Lexicology . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22.1 Identifiers . 22.2 Comments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22.3 Embedded Documentation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22.4 Reserved Words . 22.5 Expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23 Syntax - Variables and Constants . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23.1 Local Variables . . 23.2 Instance Variables . . . 23.3 Class Variables . . . 23.4 Global Variables . . 23.5 Constants . . . 23.6 Pseudo Variables . . 23.7 Pre-defined Variables . 23.8 Pre-defined Constants . . 23.9 Notes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24.1 Numerics 24.2 Strings . 24.3 Arrays . 24.4 Hashes . 24.5 Ranges . . 24 Syntax - Literals . . . . . . 25 Syntax - Operators . . 25.1 Operators 25.2 Scope . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43 45 47 49 53 55 55 55 56 57 58 62 66 67 69 69 71 71 71 71 72 72 75 77 77 77 77 78 78 79 79 79 80 80 80 81 82 85 85 87 87 87 91 92 92 95 95 96 IV
Contents . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29 Syntax - Hooks 28 Syntax - Classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26.1 Control Structures . . . 27 Syntax - Method Calls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25.3 Default scope . . 25.4 Local scope gotchas . . 25.5 Logical And . 25.6 Logical Or . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103 26 Syntax - Control Structures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109 . 27.1 Method Calls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109 . 27.2 Method Definitions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 118 . . 27.3 Dynamic methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 119 . . . 27.4 Special methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 119 . . . . 27.5 Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121 . 28.1 Class Definition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125 . 28.2 Declaring Visibility . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 129 . 28.3 Inheritance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 131 28.4 Mixing in Modules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 132 28.5 Ruby Class Meta-Model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 133 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 133 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 137 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 139 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 143 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 143 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 145 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 147 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 149 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 151 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 153 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 155 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 155 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 157 . 40.1 1. As a proxy for “each” . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 157 40.2 2. As a source of values from a block . . . . . . . . . . . . . . . . . . . . . . . . . 157 . 40.3 3. As an external iterator . . . . . . . . . . . . . . . . . . . . . . . . . . . . 158 41 Lazy evaluation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 159 42 Methods which return Enumerators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 161 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 163 43 More Enumerator readings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 165 . 44 Exception . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 167 . 45 FalseClass . 46 IO - Fiber . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 169 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 171 . 47 IO . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 171 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 171 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 171 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 171 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 173 . . . . . . . . . . . . . . 40 Forms of Enumerator . . . . . 47.1 Encoding . . 47.2 gets . 47.3 recv . . . 47.4 read . . . . 29.1 const_missing . . 30 References . . 31 Built-In Functions . . 32 Predefined Variables . 33 Predefined Classes . . . . . . . . . . . . . . . . . . . . . . . 39.1 Enumerable . 33.1 Footnotes . 34 Objects . 35 Array . 36 Class . . . 37 Comparable . 38 Encoding . . 39 Enumerable . 48 IO - File . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . V
Contents . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49 File . 49.1 File#chmod . . 49.2 File#grep . . . 49.3 File.join . . . . . . . . . . . . . 50 IO - File::Stat . . 51 File::Stat . . . 52 IO - GC . 53 GC . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54 IO - GC - Profiler . . . . . . 55 Marshal . . . . 56 Marshal . . . . 57 Method . . . . . . . 58 Math . . . . 59 Module . . . . . 60 Module - Class . . 61 NilClass . . . . . 62 Numeric . . . . 63 Numeric - Integer . . . 64 Numeric - Integer - Bignum . . 65 Numeric - Integer - Fixnum . . . 66 Numeric - Float . . . 67 Range . . . 68 Regexp . . . 69 Regexp Regular Expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 175 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 175 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 175 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 175 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 177 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 179 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 181 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 183 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 183 . 53.1 Tuning the GC . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 183 53.2 Conservative . . . 53.3 Tunning Jruby's GC. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 184 53.4 How to avoid performance penalty . . . . . . . . . . . . . . . . . . . . . . . . . . 184 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 187 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 189 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 191 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 193 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 195 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 197 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 199 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 201 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 203 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 207 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 211 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 213 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 215 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 217 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 219 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 221 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 221 69.1 oniguruma . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 221 69.2 Simplifying regexes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 221 69.3 Helper websites . . 69.4 Alternative Regular Expression Libraries . . . . . . . . . . . . . . . . . . . . . . . 222 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 223 70.1 RubyVM::InstructionSequence.disassemble . . . . . . . . . . . . . . . . . . . . . 223 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 225 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 227 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 229 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 231 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 233 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 235 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 237 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 239 . 78.1 Thread local variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 239 78.2 Joining on multiple threads . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 240 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 240 78.3 Controlling Concurrency . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 241 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 243 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 249 . 71 String . . . 72 Struct 73 Struct . . 74 Struct - Struct::Tms . . 75 Symbol . 76 Time . . . 77 Thread . 78 Thread . . 79 TrueClass . . 80 Contributors . List of Figures . . 70 RubyVM . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . VI
81 Licenses . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 253 81.1 GNU GENERAL PUBLIC LICENSE . . . . . . . . . . . . . . . . . . . . . . . . 253 81.2 GNU Free Documentation License . . . . . . . . . . . . . . . . . . . . . . . . . . 254 81.3 GNU Lesser General Public License . . . . . . . . . . . . . . . . . . . . . . . . . 254 . . . . . Contents 1
分享到:
收藏