Table of content: Preface ____ p.xii
ch. 1 Ruby Basics ____ p.1
Project Preview: The Ruby Joke Game ____ p.2
A Brief History of Computers and Computer Programming ____ p.5
The Mechanized Era ____ p.5
The First Generation ____ p.6
The Second Generation ____ p.6
The Third Generation ____ p.7
The Fourth Generation ____ p.8
The Fifth Generation ____ p.9
1990 and Beyond ____ p.9
Introducing Ruby ____ p.10
Ruby is Simple Yet Powerful ____ p.11
Ruby is Object Oriented ____ p.13
Ruby is Extremely Flexible ____ p.14
Ruby Exists in Many Different Environments ____ p.14
Getting Ready to Work with Ruby ____ p.15
Determining Whether Ruby is Already Installed ____ p.15
Installing or Upgrading Ruby ____ p.17
Working with Ruby ____ p.21
Working at the Command Prompt ____ p.21
IRB---Interactive Ruby ____ p.21
fxri-Interactive Ruby Help and Console ____ p.23
Developing Ruby Programs ____ p.24
Creating Ruby Programs on Microsoft Windows ____ p.24
Creating Ruby Programs on Mac OS X ____ p.24
Creating Ruby Programs on Linux and UNIX ____ p.24
Using a Cross-Platform Ruby Editor ____ p.24
Creating Your First Ruby Program ____ p.25
Running Your Ruby Program ____ p.26
Back to the Ruby Joke Game ____ p.27
Designing the Game ____ p.27
Running Your New Ruby Program Game ____ p.32
Summing Up ____ p.35
Comprehension Check ____ p.36
Reinforcement Exercises ____ p.38
Discovery Projects ____ p.39
ch. 2 Interacting with Ruby ____ p.41
Project Preview: The Ruby Tall Tale Game ____ p.42
Getting to Know IRB ____ p.46
Starting an IRB Session ____ p.46
Working with Multiple IRB Sessions ____ p.48
Accessing IRB Online ____ p.48
Working with IRB ____ p.49
Executing Ruby Statements ____ p.49
Following Ruby's Syntax Rules ____ p.50
Executing Incomplete Statements ____ p.51
Using IRB to Test Ruby Scripts ____ p.51
Using IRB to Perform Mathematical Calculations ____ p.53
Using IRB as a Calculator ____ p.53
Accessing Methods Stored in the Math Module ____ p.54
Operator Precedence ____ p.54
Overriding Operator Precedence ____ p.55
Integers Versus Floating-Point Numbers ____ p.56
Accessing Ruby Documentation ____ p.56
Back to the Ruby Tall Tale Game ____ p.59
Designing the Ruby Tall Tale Game ____ p.60
Running Your New Ruby Script Game ____ p.65
Summing Up ____ p.70
Comprehension Check ____ p.71
Reinforcement Exercises ____ p.74
Discovery Projects ____ p.75
ch. 3 Working with Strings, Objects, and Variables ____ p.77
Project Preview: The Ruby Virtual Crazy 8-Ball Game ____ p.78
Creating and Formatting Text Strings ____ p.81
Modifying Text String Format ____ p.82
String Interpolation ____ p.83
Manipulating String Contents ____ p.83
Concatenating Text Strings ____ p.84
Multiplying Text Strings ____ p.84
Comparing Text Strings ____ p.85
Creating Multiline Text Strings ____ p.85
Working with String Class Methods ____ p.87
Object-Oriented Programming ____ p.88
Defining a New Class ____ p.88
Defining Class Properties ____ p.89
Instantiating and Interacting with New Objects ____ p.89
Defining Class Methods ____ p.90
Inheritance ____ p.91
Converting from One Class to Another ____ p.92
Implicit Class Conversion ____ p.93
Explicit Class Conversion ____ p.93
Storing and Retrieving Data ____ p.95
Naming Variables ____ p.96
Variable Assignments ____ p.96
Variable Scope ____ p.97
Storing Data That Does Not Change ____ p.98
Back to the Ruby Virtual Crazy 8-Ball Game ____ p.100
Designing the Game ____ p.100
Running Your New Ruby Script Game ____ p.107
Summing Up ____ p.107
Comprehension Check ____ p.108
Reinforcement Exercises ____ p.111
Discovery Projects ____ p.112
ch. 4 Implementing Conditional Logic ____ p.114
Project Preview: The Ruby Typing Challenge Game ____ p.115
Using Conditional Logic to Create Adaptive Scripts ____ p.119
Performing Alternative Types of Comparisons ____ p.121
Conditional Logic Modifiers ____ p.122
The if Modifier ____ p.122
The unless Modifier ____ p.122
Working with if and unless Expressions ____ p.123
Creating if Expressions ____ p.123
Replacing if Modifiers with if Expressions ____ p.124
Creating unless Expressions ____ p.126
Using case Blocks to Analyze Data ____ p.127
Using the Ternary Operator ____ p.129
Nesting Conditional Statements ____ p.129
Combining and Negating Logical Comparison Operations ____ p.130
Back to the Ruby Typing Challenge Game ____ p.132
Designing the Game ____ p.132
Running Your New Ruby Script Game ____ p.140
Summing Up ____ p.140
Comprehension Check ____ p.141
Reinforcement Exercises ____ p.144
Discovery Projects ____ p.145
ch. 5 Working with Loops ____ p.146
Project Preview: The Superman Movie Trivia Quiz ____ p.147
Understanding Loops ____ p.150
Using Language Constructs to Create Loops ____ p.151
Working with while Loops ____ p.151
Working with until Loops ____ p.152
Working with for...in Loops ____ p.153
Using Loop Modifiers ____ p.154
The while Modifier ____ p.154
The until Modifier ____ p.155
Executing Looping Methods ____ p.156
Working with the each Method ____ p.156
Working with the times Method ____ p.157
Working with the upto Method ____ p.158
Working with the downto Method ____ p.159
Working with the step Method ____ p.160
Working with the loop Method ____ p.161
Altering Loop Execution ____ p.162
Prematurely Terminating Loop Execution ____ p.162
Repeating the Current Execution of a Loop ____ p.163
Skipping to the Next Iteration of a Loop ____ p.163
Restarting a Loop from the Beginning ____ p.164
Back to the Superman Movie Trivia Quiz ____ p.165
Designing the Game ____ p.165
Running Your New Ruby Script Game ____ p.174
Summing Up ____ p.174
Comprehension Check ____ p.175
Reinforcement Exercises ____ p.178
Discovery Projects ____ p.179
ch. 6 Working with Collections of Data ____ p.181
Project Preview: The Ruby Number Guessing Game ____ p.182
Storing and Manipulating Lists Using Arrays ____ p.186
Managing Data Using Arrays ____ p.186
Replacing and Adding Array Items ____ p.188
Determining if an Array is Empty ____ p.190
Retrieving Items from an Array ____ p.190
Using a Loop to Iterate Through the Contents of an Array ____ p.192
Deleting Items from an Array ____ p.192
Sorting the Contents of an Array Alphabetically ____ p.194
Sorting Array Contents in Reverse Alphabetical Order ____ p.194
Searching an Array ____ p.195
Storing and Manipulating Lists Using Hashes ____ p.196
Creating a Hash ____ p.196
Adding a Hash's Key-Value Pairs ____ p.198
Deleting a Hash's Key-Value Pairs ____ p.199
Determining the Number of Key-Value Pairs in a Hash ____ p.200
Retrieving Data Stored in Hashes ____ p.201
Sorting Hash keys ____ p.202
Back to the Ruby Number Guessing Game ____ p.204
Designing the Game ____ p.204
Running Your New Ruby Script Game ____ p.212
Summing Up ____ p.212
Comprehension Check ____ p.214
Reinforcement Exercises ____ p.217
Discovery Projects ____ p.219
ch. 7 Working with Regular Expressions ____ p.221
Project Preview: The Ruby Word Guessing Game ____ p.222
Using Regular Expressions for Data Validation ____ p.227
Matching Basic Patterns ____ p.228
Matching Specific Patterns ____ p.228
Matching Multiple Patterns ____ p.228
Working with Metacharacters ____ p.230
Escaping Metacharacters ____ p.231
Matching Individual Characters ____ p.231
Matching a Pattern at the Beginning of a String ____ p.231
Matching a Pattern at the End of a String ____ p.232
Matching Once or Not at All ____ p.232
Matching Zero or More Times ____ p.232
Matching Any of a Collection of Characters ____ p.233
Other Uses for Regular Expressions ____ p.233
Overcoming Differences in Case ____ p.234
String Substitution ____ p.234
Back to the Ruby Word Guessing Game ____ p.236
Designing the Game ____ p.236
Running Your New Ruby Script Game ____ p.249
Summing Up ____ p.249
Comprehension Check ____ p.251
Reinforcement Exercises ____ p.254
Discovery Projects ____ p.255
ch. 8 Object-Oriented Programming ____ p.257
Project Preview: The Rock, Paper, Scissors Game ____ p.258
Key Features of Object-Oriented Programming ____ p.262
Abstraction ____ p.262
Encapsulation ____ p.263
Inheritance ____ p.266
Polymorphism ____ p.267
Initializing Objects Upon Instantiation ____ p.269
Understanding Variable Scope ____ p.271
Working with Local Variables ____ p.271
Working with Global Variables ____ p.271
Working with Instance Variables ____ p.273
Working with Class Variables ____ p.273
Taking Advantage of Ruby's Built-in Classes ____ p.274
Modifying Ruby Classes ____ p.275
Back to the Rock, Paper, Scissors Game ____ p.277
Designing the Game ____ p.277
Running Your New Ruby Program Game ____ p.286
Summing Up ____ p.286
Comprehension Check ____ p.287
Reinforcement Exercises ____ p.290
Discovery Projects ____ p.292
ch. 9 File and Folder Administration ____ p.294
Project Preview: The Ruby Blackjack Game ____ p.295
Redirecting File Input and Output ____ p.299
Administering Text Files and Folders ____ p.300
Verifying Whether a File or Folder Exists ____ p.300
Retrieving Information About a File or Folder ____ p.301
Creating New Folders ____ p.303
Deleting Files and Folders ____ p.304
Renaming Files ____ p.304
Working with Files and Folders on Different Operating Systems ____ p.305
Reading From and Writing to Text Files ____ p.306
Writing Data to Text Files ____ p.307
Appending Data to the End of Text Files ____ p.308
Reading Data from Text Files ____ p.309
Back to the Ruby Blackjack Game ____ p.311
Designing the Game ____ p.311
Running Your New Ruby Script Game ____ p.321
Summing Up ____ p.322
Comprehension Check ____ p.323
Reinforcement Exercises ____ p.326
Discovery Projects ____ p.329
ch. 10 Debugging ____ p.331
Project Preview: The Ruby Tic-Tac-Toe Game ____ p.332
Types of Script Errors ____ p.335
Syntax Errors ____ p.336
Runtime Errors ____ p.336
Logical Errors ____ p.337
Handling Exceptions ____ p.337
Creating Exception Handlers ____ p.337
Accessing Error Information ____ p.338
Handling Different Types of Errors ____ p.339
Retrying Failed Statements ____ p.339
Tracking a Script's Logical Flow ____ p.341
Finding Bugs Using the Ruby Debugger ____ p.342
Starting the Debugger ____ p.342
Back to the Ruby Tic-Tac-Toe Game ____ p.347
Designing the Game ____ p.347
Running Your New Ruby Script Game ____ p.359
Summing Up ____ p.360
Comprehension Check ____ p.361
Reinforcement Exercises ____ p.364
Discovery Projects ____ p.366
ch. 11 Ruby on Rails Web Development ____ p.368
Project Preview: The Blog Application ____ p.369
Overview of Ruby on Rails ____ p.369
Skills Needed to Work with Ruby on Rails ____ p.371
Required Software ____ p.371
Development Philosophy ____ p.371
Architecture ____ p.372
Working with Database Management Systems ____ p.374
Getting Ruby on Rails Up and Running ____ p.375
Installing Ruby On Rails ____ p.375
Selecting a Web Server ____ p.377
Installing the SQLite Database Management System ____ p.377
Verifying Ruby on Rails Setup ____ p.377
Creating a Demo Application ____ p.378
Verifying the Execution of Your Web Server ____ p.379
Ruby on Rails Applications Files ____ p.381
Back to the Blog Application ____ p.384
Design the Blog Application ____ p.384
Running Your New Ruby on Rails Project ____ p.386
Learning More About Ruby on Rails ____ p.387
Summing Up ____ p.388
Comprehension Check ____ p.390
Reinforcement Exercises ____ p.393
Discovery Projects ____ p.400
Glossary ____ p.401
Index ____ p.407
· · · · · · (
收起)