search for books and compare prices
Tables of Contents for Sams Teach Yourself Ruby in 21 Days
Chapter/Section Title
Page #
Page Count
Introduction
1
8
Week 1 The Fundamentals
9
152
Getting Started with Ruby
11
16
Why Ruby?
11
3
Ruby Is Small and Intuitive
12
1
Ruby Gives You Immediate Feedback
12
1
Ruby Is Free
12
1
Ruby Is Portable
12
1
Ruby Is Object-Oriented
13
1
Ruby Is a Scripting Language
13
1
Ruby Supports Regular Expressions
14
1
Make Sure You Have Ruby
14
1
First Steps
14
7
Life in the Command Line
15
1
Choosing a Text Editor
15
1
Our First Script
16
1
Some Experiments
16
1
Play-by-Play
17
1
Remarks About the Experimental Results
18
2
The Shebang Line
20
1
Using Ruby Interactively
21
3
An Interactive Tool: irb
22
1
The eval.rb Script
23
1
Summary
24
1
Is There Homework in This Class?
24
3
Exercises
25
1
Answers
25
2
Hello, Objects!
27
24
What Is an Object?
27
1
The First Object: self
28
2
Teach Yourself Tricks
29
1
The Second Object: other
30
2
Classes
32
5
Making Instances of a Class
33
1
Appending Methods to a Class
34
1
Altering and Removing Methods
35
1
Everybody's Methods
36
1
Who Is This ``self'' Anyway?
37
8
Method Arguments
38
2
Local Scope for Variables
40
2
Communication Within an Object
42
2
Communication Between Different Objects
44
1
Identifiers and Variables
45
1
Name Tags, Not Suitcases
45
2
Summary
47
4
Exercises
48
1
Answers
48
3
Containers
51
18
A Change in Convention
51
1
Some Words About Ambiguity
52
2
Back to Business
54
1
Strings
54
5
Specifying Substrings by Position
54
2
Individual Characters
56
1
Specifying Substrings by Matching
57
1
A Few Useful String Instance Methods
58
1
Arrays
59
5
Arrays Containing Arrays
61
1
FIFOs and Stacks
62
1
Stacks
63
1
A Few Useful Array Instance Methods
63
1
Hashes
64
2
A Few Useful Hash Instance Methods
65
1
Ranges
66
1
Summary
67
2
Exercises
67
1
Answers
67
2
Iteration and Flow Control
69
24
Using Iterators
69
7
each
70
1
Variations on Iterator Calls
71
1
times, downto, upto, step
72
1
each_byte
73
1
each_index, each_with_index
74
1
each_pair, each_key, each_value for Hashes
74
1
select, map
75
1
Flow Control
76
10
Conditional Code
76
2
Loops
78
1
A Text Filter
78
2
Interrupting the Flow
80
1
Odd-Position Elements
81
2
Testing Multiple Conditions
83
1
Getting a Value from if or case
84
2
Grouping Several Expressions into One
86
1
Why Loop When You Can Iterate?
86
1
Summary
86
7
Exercises
87
2
Answers
89
4
The Characteristics of Objects
93
20
Instance Variables
94
13
Mars and the Metric System: A Cautionary Tale
95
1
Writing a Temperature Class
96
2
Integers and Floats
98
1
A Convention for Naming Methods
98
1
Automatic Accessors
99
1
Define Your Own Operators
100
3
Class Constants
103
2
Access Control (or, A Cure for the Common Code)
105
1
The initialize Method
105
2
Global Variables
107
1
What to Name Things
108
5
Exercises
109
1
Answers
110
3
Ins and Outs
113
24
Streams
113
7
The Standard Streams
114
2
Files
116
1
Some Useful IO Methods
117
3
What About Memory Space?
120
1
Formatted Output
121
2
Class Methods
123
4
Some Useful File Class Methods
125
2
The Command Line
127
1
Class Variables
128
2
Errors and Exceptions
130
2
Summary
132
5
Exercises
132
1
Answers
133
4
Catching Up on Details
137
24
Numbers in Ruby
138
8
Integer Literals
138
1
Floating-Point Literals
139
1
How Numbers Are Stored
140
2
How Numbers Are Presented
142
1
Binary Arithmetic
143
3
Boolean Logic
146
2
Short-Circuit Evaluation
147
1
Strings and String Literals
148
3
Block Scope for Local Variables
151
1
Shortcuts and Tricks
151
4
Variable Modification
151
1
Chained Assignment
152
1
Multiple Assignment
153
2
Functional and Imperative Styles
155
2
Garbage Collection
155
1
Gotchas
156
1
Summary
157
4
Exercises
157
2
Answers
159
2
Week 2 Power Scripting
161
150
Pattern Matching
163
22
Simple Pattern Matching
164
4
Wildcards and Character Classes
165
1
Character Ranges
166
1
Negation
166
1
Abbreviations
167
1
Position Anchors
168
1
Repetition
169
3
Greed
171
1
Grouping
172
6
Grouping and Repetition
172
4
Grouping and Alternation
176
1
Grouping and Memory
177
1
Switches
178
1
Case Insensitivity: /i
178
1
Extended Legibility: /x
178
1
Multiline Matching: /m
178
1
Some Container Methods That Use Regexes
178
2
Regexes and Matches As Objects
180
1
Summary
181
4
Exercises
181
1
Answers
182
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 Basics
186
1
Inheritance
187
2
Fiddling with Inheritance
189
4
Play It Again, Ruby: Another Method Call Example
193
2
Modules
195
2
Resolving Method Ambiguities
197
1
Summary
198
5
Exercises
198
2
Answers
200
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
Compiled Extensions
209
2
require and Variables
210
1
require Versus include
211
1
Examining the Ruby Installation
211
2
Abstraction and the General Case
213
5
Under- and Over-Abstraction
214
1
Getting Abstraction Right
215
3
Summary
218
5
Exercises
218
2
Answers
220
3
Modules and Classes in Depth
223
24
Designing Modules and Classes for Clarity and Reuse
223
6
Some Class/Module Distinctions
224
2
An Exercise in Adjectival Thinking
226
3
Code Reusability
229
1
Embedded Modules and Namespace Management
229
5
Modules Mixing in Modules
231
1
Classes Defined Inside Modules
232
1
Classes Defined Inside Classes
233
1
Class-Module Distribution Across Program Files
234
1
Overriding Methods
235
4
Overriding and Aliasing
236
1
Overriding an Inherited Method
237
2
Handling Arguments in Overridden Methods
239
1
Summary
239
8
Exercises
240
4
Answers
244
3
An Introduction to Recursion
247
18
The Canonical Starting Point: Factorials
247
3
A Little Too Much Like Magic?
249
1
Recursive Functions
250
1
Efficiency Concerns
250
4
Memoization
252
2
The Towers of Hanoi
254
7
Summary
261
4
Exercises
261
2
Answers
263
2
Mastering the Operating System
265
24
Motivation
265
1
Portability Notes
266
1
Gathering Information
267
2
Treating Programs As Functions
269
3
Extended Conversations
272
3
The Art of Instant Reproduction
275
3
Waiting for Children
277
1
Pipes
277
1
How to Control Your Children
278
11
Example Spinner #1, Using fork
279
2
Example Spinner #2, Using IO.popen
281
2
Example Spinner #3, Using Kernel.open
283
1
Summary
283
1
Exercises
284
1
Answers
285
4
Arguments, Blocks, and Procs
289
22
Life Without Iterators
290
7
Stealthy Approach
291
1
A Hands-on Approach
292
1
A Hands-off Approach
293
2
Final Approach: Very Hands-off
295
2
Writing Iterator Methods
297
6
Hybrid Iterators
298
1
New Iterators for Old Classes
299
2
Was This Trip Really Necessary?
301
1
select_by_index
302
1
Other Uses for Blocks
303
1
Summary
304
7
Exercises
306
1
Answers
306
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
Initialization
315
1
Storing and Retrieving Elements
316
2
Accessing Dimensions
318
1
Viewing a Matric As a Whole
319
2
Providing Iterators
321
1
Doing the Math
322
2
Multipurpose Methods
324
2
A Versatile Constructor Using Default Values
326
1
A More Versatile Constructor
327
4
Summary
331
6
Exercises
332
1
Answers
333
4
Putting It Together (Part I)
337
18
The Unjumbler
337
10
Getting the Permutations
338
3
Finding the Needles in the Haystack
341
2
Finished Product
343
1
A Portable is_word? Function
344
1
Bailing Out Early
345
1
Resorting to Wizardry
346
1
Notes on Language Enhancement
347
1
An Interactive Process Killer
348
1
A Little About the Unix Tools
348
2
Designing from the Top Down
350
Summary
331
24
Ruby/Tk
355
34
What Is Tk?
357
1
Our First Tk Application
357
3
Geometry Managers
360
2
Entry Widgets and Buttons
362
4
Some Other Widgets
366
9
More Complex Coding
375
1
Summary
376
13
Exercises
377
1
Answers
378
11
Ruby/Gtk
389
38
Installation under UNIX
390
1
Installation under Windows
391
1
First Ruby/Gtk Scripts
392
2
Simple Widget Layout
394
6
Bin Containers
394
1
Box Containers
395
4
Table Containers
399
1
Modular Design for Multiple Windows
400
6
Window Subclasses and Test Code
400
1
A Table Window
400
2
An Application Split into two Files
402
1
Modal Dialogs
403
1
The Messagebox Class
403
3
More Widget Types
406
5
Checkbutton and Radiobutton
406
2
AccelGroup, ToggleButton, and HSeparator
408
1
Text
409
2
ScrollableWindow
411
1
A Full Ruby/Gtk Application
411
8
Summary
419
8
Exercises
420
1
Answers
421
6
Some Advanced Topics (That Aren't So Hard)
427
22
Sockets
428
12
``Hello, World'' Using TCP
429
1
``Hello, World'' Using UDP
430
2
A TCP Chat Session
432
1
A Simple Web Server
433
5
Supporting Concurrent Sessions
438
2
Threads
440
6
Passing Control Around
442
2
Establishing a Pecking Order
444
1
The Bathroom Pass
445
1
When to Thread and When to Fork
446
1
Summary
446
3
Exercises
447
1
Answers
447
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 Documents
452
1
Enable SHTML
453
1
Enable CGI
453
1
Set a Uses ID
454
1
Activate the New Configuration
454
1
Test Drives
454
4
Using Ruby to Generate an HTML File Directly
455
1
A First CGI Script
456
1
A First SHTML Script
457
1
Know Thy Client
458
5
Remember the Past
460
1
Use DBM to Remember Old Session Information
461
2
Object-Oriented CGI Support
463
5
Session Information Using the CGI Class
465
1
Persistent Session Information
466
2
Embedded Ruby
468
2
Summary
470
5
Exercises
470
1
Answers
471
4
Putting It Together (Part II)
475
24
Binary Decision Trees
476
15
Script Overview
478
1
The BDT Class and Its Relatives
478
2
The BDT-sample Class
480
1
A Mild Dose of Information Theory
481
1
The BDT-set Class
482
3
The Full Script
485
4
A Test of Intelligence
489
1
Ideas for Improvements and Enhancements
490
1
Tk-based Peer Chat
491
7
What Do We Mean by ``Peer''?
492
1
Top-Level Scripts
493
1
The TkChat class
494
2
Testing the Scripts
496
1
Ideas for Improvements and Enhancements
497
1
Summary
498
1
Appendices
499
22
Appendix A irb Results
501
2
Appendix B Installation Help
503
6
Unix
503
1
Step 1. Download the Source Code
504
1
Step 2. Unpack the Archive
504
1
Step 3. Prepare for Compiling
504
1
Step 4. make the Interpreter
505
1
Step 5. Test Before Installing
505
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 Accessibility
506
1
Step 8. Set Up the emacs Ruby Mode (Optional)
506
1
Microsoft Windows
507
1
The ``One-Click'' Installer
507
1
Unix Wannabe Installation for Windows
507
2
Appendix C Debugging, With and Without a Debugger
509
8
Stack Traces
509
2
Inline Diagnostics
511
1
The Built-In Debugger
512
5
Appendix D Essential Vocabulary
517
4
Index
521
<