search for books and compare prices
Tables of Contents for Sams Teach Yourself Ruby in 21 Days
Week 1 The Fundamentals
9
152
Getting Started with Ruby
11
16
Ruby Is Small and Intuitive12
1
Ruby Gives You Immediate Feedback12
1
Ruby Is Free12
1
Ruby Is Portable12
1
Ruby Is Object-Oriented13
1
Ruby Is a Scripting Language13
1
Ruby Supports Regular Expressions14
1
Make Sure You Have Ruby
14
1
Life in the Command Line15
1
Choosing a Text Editor15
1
Our First Script16
1
Some Experiments16
1
Play-by-Play17
1
Remarks About the Experimental Results18
2
The Shebang Line20
1
Using Ruby Interactively
21
3
An Interactive Tool: irb22
1
The eval.rb Script23
1
Is There Homework in This Class?
24
3
Exercises25
1
Answers25
2
The First Object: self
28
2
Teach Yourself Tricks29
1
The Second Object: other
30
2
Making Instances of a Class33
1
Appending Methods to a Class34
1
Altering and Removing Methods35
1
Everybody's Methods36
1
Who Is This ``self'' Anyway?
37
8
Method Arguments38
2
Local Scope for Variables40
2
Communication Within an Object42
2
Communication Between Different Objects44
1
Identifiers and Variables45
1
Name Tags, Not Suitcases
45
2
Exercises48
1
Answers48
3
A Change in Convention
51
1
Some Words About Ambiguity
52
2
Specifying Substrings by Position54
2
Individual Characters56
1
Specifying Substrings by Matching57
1
A Few Useful String Instance Methods58
1
Arrays Containing Arrays61
1
FIFOs and Stacks62
1
Stacks63
1
A Few Useful Array Instance Methods63
1
A Few Useful Hash Instance Methods65
1
Exercises67
1
Answers67
2
Iteration and Flow Control
69
24
each70
1
Variations on Iterator Calls71
1
times, downto, upto, step72
1
each_byte73
1
each_index, each_with_index74
1
each_pair, each_key, each_value for Hashes74
1
select, map75
1
Conditional Code76
2
Loops78
1
A Text Filter78
2
Interrupting the Flow80
1
Odd-Position Elements81
2
Testing Multiple Conditions83
1
Getting a Value from if or case84
2
Grouping Several Expressions into One86
1
Why Loop When You Can Iterate?86
1
Exercises87
2
Answers89
4
The Characteristics of Objects
93
20
Mars and the Metric System: A Cautionary Tale95
1
Writing a Temperature Class96
2
Integers and Floats98
1
A Convention for Naming Methods98
1
Automatic Accessors99
1
Define Your Own Operators100
3
Class Constants103
2
Access Control (or, A Cure for the Common Code)105
1
The initialize Method105
2
Exercises109
1
Answers110
3
The Standard Streams114
2
Files116
1
Some Useful IO Methods117
3
What About Memory Space?
120
1
Some Useful File Class Methods125
2
Errors and Exceptions
130
2
Exercises132
1
Answers133
4
Catching Up on Details
137
24
Integer Literals138
1
Floating-Point Literals139
1
How Numbers Are Stored140
2
How Numbers Are Presented142
1
Binary Arithmetic143
3
Short-Circuit Evaluation147
1
Strings and String Literals
148
3
Block Scope for Local Variables
151
1
Variable Modification151
1
Chained Assignment152
1
Multiple Assignment153
2
Functional and Imperative Styles
155
2
Garbage Collection155
1
Gotchas156
1
Exercises157
2
Answers159
2
Week 2 Power Scripting
161
150
Simple Pattern Matching
164
4
Wildcards and Character Classes165
1
Character Ranges166
1
Negation166
1
Abbreviations167
1
Greed171
1
Grouping and Repetition172
4
Grouping and Alternation176
1
Grouping and Memory177
1
Case Insensitivity: /i178
1
Extended Legibility: /x178
1
Multiline Matching: /m178
1
Some Container Methods That Use Regexes
178
2
Regexes and Matches As Objects
180
1
Exercises181
1
Answers182
3
Inheritance and Modules
185
18
Organizing Organization
185
1
The Make-Up of Ruby Classes: Some ``What'' and a Little ``How''
186
3
The Basics186
1
Inheritance187
2
Fiddling with Inheritance
189
4
Play It Again, Ruby: Another Method Call Example
193
2
Resolving Method Ambiguities
197
1
Exercises198
2
Answers200
3
Program File Layout, Program Design, and the General Case
203
20
Program and File Interaction
204
1
Runtime Extension of Ruby's World: require
205
3
The Argument to require
208
1
require and Variables210
1
require Versus include211
1
Examining the Ruby Installation
211
2
Abstraction and the General Case
213
5
Under- and Over-Abstraction214
1
Getting Abstraction Right215
3
Exercises218
2
Answers220
3
Modules and Classes in Depth
223
24
Designing Modules and Classes for Clarity and Reuse
223
6
Some Class/Module Distinctions224
2
An Exercise in Adjectival Thinking226
3
Code Reusability229
1
Embedded Modules and Namespace Management
229
5
Modules Mixing in Modules231
1
Classes Defined Inside Modules232
1
Classes Defined Inside Classes233
1
Class-Module Distribution Across Program Files
234
1
Overriding and Aliasing236
1
Overriding an Inherited Method237
2
Handling Arguments in Overridden Methods239
1
Exercises240
4
Answers244
3
An Introduction to Recursion
247
18
The Canonical Starting Point: Factorials
247
3
A Little Too Much Like Magic?249
1
Recursive Functions250
1
Memoization252
2
Exercises261
2
Answers263
2
Mastering the Operating System
265
24
Gathering Information
267
2
Treating Programs As Functions
269
3
Extended Conversations
272
3
The Art of Instant Reproduction
275
3
Waiting for Children277
1
Pipes277
1
How to Control Your Children
278
11
Example Spinner #1, Using fork279
2
Example Spinner #2, Using IO.popen281
2
Example Spinner #3, Using Kernel.open283
1
Summary283
1
Exercises284
1
Answers285
4
Arguments, Blocks, and Procs
289
22
Life Without Iterators
290
7
Stealthy Approach291
1
A Hands-on Approach292
1
A Hands-off Approach293
2
Final Approach: Very Hands-off295
2
Writing Iterator Methods
297
6
Hybrid Iterators298
1
New Iterators for Old Classes299
2
Was This Trip Really Necessary?301
1
select_by_index302
1
Other Uses for Blocks
303
1
Exercises306
1
Answers306
5
Week 3 Making It Work for You
311
188
Toward Habitable Interfaces
313
24
Interface Size and Intuitiveness
314
1
An IntegerMatrix Class
315
16
Initialization315
1
Storing and Retrieving Elements316
2
Accessing Dimensions318
1
Viewing a Matric As a Whole319
2
Providing Iterators321
1
Doing the Math322
2
Multipurpose Methods324
2
A Versatile Constructor Using Default Values326
1
A More Versatile Constructor327
4
Exercises332
1
Answers333
4
Putting It Together (Part I)
337
18
Getting the Permutations338
3
Finding the Needles in the Haystack341
2
Finished Product343
1
A Portable is_word? Function344
1
Bailing Out Early345
1
Resorting to Wizardry346
1
Notes on Language Enhancement
347
1
An Interactive Process Killer
348
1
A Little About the Unix Tools348
2
Designing from the Top Down350
Our First Tk Application
357
3
Entry Widgets and Buttons
362
4
Exercises377
1
Answers378
11
Installation under UNIX
390
1
Installation under Windows
391
1
First Ruby/Gtk Scripts
392
2
Bin Containers394
1
Box Containers395
4
Table Containers399
1
Modular Design for Multiple Windows
400
6
Window Subclasses and Test Code400
1
A Table Window400
2
An Application Split into two Files402
1
Modal Dialogs403
1
The Messagebox Class403
3
Checkbutton and Radiobutton406
2
AccelGroup, ToggleButton, and HSeparator408
1
Text409
2
ScrollableWindow411
1
A Full Ruby/Gtk Application
411
8
Exercises420
1
Answers421
6
Some Advanced Topics (That Aren't So Hard)
427
22
``Hello, World'' Using TCP429
1
``Hello, World'' Using UDP430
2
A TCP Chat Session432
1
A Simple Web Server433
5
Supporting Concurrent Sessions438
2
Passing Control Around442
2
Establishing a Pecking Order444
1
The Bathroom Pass445
1
When to Thread and When to Fork446
1
Exercises447
1
Answers447
2
Working with the Web
449
26
Static Content Versus Dynamic Content
450
1
Server-Side Versus Client-Side
450
1
Privileges at the Server
451
1
Configuring Apache: httpd.conf
452
2
Choose a Root Directory for Web Documents452
1
Enable SHTML453
1
Enable CGI453
1
Set a Uses ID454
1
Activate the New Configuration454
1
Using Ruby to Generate an HTML File Directly455
1
A First CGI Script456
1
A First SHTML Script457
1
Remember the Past460
1
Use DBM to Remember Old Session Information461
2
Object-Oriented CGI Support
463
5
Session Information Using the CGI Class465
1
Persistent Session Information466
2
Exercises470
1
Answers471
4
Putting It Together (Part II)
475
24
Binary Decision Trees
476
15
Script Overview478
1
The BDT Class and Its Relatives478
2
The BDT-sample Class480
1
A Mild Dose of Information Theory481
1
The BDT-set Class482
3
The Full Script485
4
A Test of Intelligence489
1
Ideas for Improvements and Enhancements490
1
What Do We Mean by ``Peer''?492
1
Top-Level Scripts493
1
The TkChat class494
2
Testing the Scripts496
1
Ideas for Improvements and Enhancements497
1
Appendix A irb Results
501
2
Appendix B Installation Help
503
6
Unix503
1
Step 1. Download the Source Code504
1
Step 2. Unpack the Archive504
1
Step 3. Prepare for Compiling504
1
Step 4. make the Interpreter505
1
Step 5. Test Before Installing505
1
Step 6a. Install (If You're the Administrator)505
1
Step 6b. Update PATH (If You're Not the Administrator)506
1
Step 7. Test Accessibility506
1
Step 8. Set Up the emacs Ruby Mode (Optional)506
1
Microsoft Windows507
1
The ``One-Click'' Installer507
1
Unix Wannabe Installation for Windows507
2
Appendix C Debugging, With and Without a Debugger
509
8
Stack Traces509
2
Inline Diagnostics511
1
The Built-In Debugger512
5
Appendix D Essential Vocabulary
517
4
<