| |
| |
Foreword | |
| |
| |
About the Author | |
| |
| |
About the Technical Reviewers | |
| |
| |
Acknowledgments | |
| |
| |
Introduction | |
| |
| |
| |
Foundations and Scaffolding | |
| |
| |
| |
Let's Get It Started: Installing Ruby | |
| |
| |
Installing Ruby | |
| |
| |
Windows | |
| |
| |
Apple Mac OS X | |
| |
| |
Linux | |
| |
| |
Other Platforms | |
| |
| |
Summary | |
| |
| |
| |
Programming == Joy: A Whistle-Stop Tour of Ruby and Object Orientation | |
| |
| |
Baby Steps | |
| |
| |
Irb: interactive Ruby | |
| |
| |
Ruby Is English for Computers | |
| |
| |
Why Ruby Makes a Great Programming Language | |
| |
| |
Trails for the Mind | |
| |
| |
Turning Ideas into Ruby Code | |
| |
| |
How Ruby Understands Concepts with Objects and Classes | |
| |
| |
The Making of a Man | |
| |
| |
Basic Variables | |
| |
| |
From People to Pets | |
| |
| |
Everything Is an Object | |
| |
| |
Kernel Methods | |
| |
| |
Passing Data to Methods | |
| |
| |
Using the Methods of the String Class | |
| |
| |
Using Ruby Without Object Orientation | |
| |
| |
Summary | |
| |
| |
| |
Ruby's Building Blocks: Data, Expressions, and Flow Control | |
| |
| |
Numbers and Expressions | |
| |
| |
Basic Expressions | |
| |
| |
Variables | |
| |
| |
Comparison Operators and Expressions | |
| |
| |
Looping Through Numbers with Blocks and Iterators | |
| |
| |
Floating Point Numbers | |
| |
| |
Constants | |
| |
| |
Text and Strings | |
| |
| |
String Literals | |
| |
| |
String Expressions | |
| |
| |
Interpolation | |
| |
| |
String Methods | |
| |
| |
Regular Expressions and String Manipulation | |
| |
| |
Arrays and Lists | |
| |
| |
Basic Arrays | |
| |
| |
Splitting Strings Into Arrays | |
| |
| |
Array Iteration | |
| |
| |
Other Array Methods | |
| |
| |
Hashes | |
| |
| |
Basic Hash Methods | |
| |
| |
Hashes Within Hashes | |
| |
| |
Flow Control | |
| |
| |
If and unless | |
| |
| |
?:, The Ternary Operator | |
| |
| |
Elsif and case | |
| |
| |
While and until | |
| |
| |
Code Blocks | |
| |
| |
Other Useful Building Blocks | |
| |
| |
Dates and Times | |
| |
| |
Large Numbers | |
| |
| |
Ranges | |
| |
| |
Symbols | |
| |
| |
Converting Between Classes | |
| |
| |
Summary | |
| |
| |
| |
Developing a Basic Ruby Application | |
| |
| |
Working with Source Code Files | |
| |
| |
Creating a Test File | |
| |
| |
The Test Source Code File | |
| |
| |
Running Your Source Code | |
| |
| |
Our Application: A Text Analyzer | |
| |
| |
Required Basic Features | |
| |
| |
Building the Basic Application | |
| |
| |
Obtaining Some Dummy Text | |
| |
| |
Loading Text Files and Counting Lines | |
| |
| |
Counting Characters | |
| |
| |
Counting Words | |
| |
| |
Counting Sentences and Paragraphs | |
| |
| |
Calculating Averages | |
| |
| |
The Source Code So Far | |
| |
| |
Adding Extra Features | |
| |
| |
Percentage of "Useful" Words | |
| |
| |
Summarizing by Finding "Interesting" Sentences | |
| |
| |
Analyzing Files Other than text.txt | |
| |
| |
The Completed Program | |
| |
| |
Summary | |
| |
| |
| |
The Ruby Ecosystem | |
| |
| |
Ruby's History | |
| |
| |
The Land of the Rising Sun | |
| |
| |
Ruby's Influences | |
| |
| |
Go West | |
| |
| |
Ruby on Rails | |
| |
| |
Why Rails Came into Existence | |
| |
| |
How the Web (2.0) Was Won | |
| |
| |
The Open Source Culture | |
| |
| |
What Is Open Source? | |
| |
| |
Where and How to Get Help | |
| |
| |
Mailing Lists | |
| |
| |
Usenet Newsgroups | |
| |
| |
Internet Relay Chat (IRC) | |
| |
| |
Documentation | |
| |
| |
Forums | |
| |
| |
Joining the Community | |
| |
| |
Give Help to Others | |
| |
| |
Contribute Code | |
| |
| |
Weblogs | |
| |
| |
Summary | |
| |
| |
| |
The Core of Ruby | |
| |
| |
| |
Classes, Objects, and Modules | |
| |
| |
Why Use Object Orientation? | |
| |
| |
Object Orientation Basics | |
| |
| |
Local, Global, Object, and Class Variables | |
| |
| |
Class Methods vs. Object Methods | |
| |
| |
Inheritance | |
| |
| |
Overriding Existing Methods | |
| |
| |
Reflection and Discovering an Object's Methods | |
| |
| |
Encapsulation | |
| |
| |
Polymorphism | |
| |
| |
Nested Classes | |
| |
| |
The Scope of Constants | |
| |
| |
Modules, Namespaces, and Mix-Ins | |
| |
| |
Namespaces | |
| |
| |
Mix-ins | |
| |
| |
Building a Dungeon Text Adventure with Objects | |
| |
| |
Dungeon Concepts | |
| |
| |
Creating the Initial Classes | |
| |
| |
Structs: Quick and Easy Data Classes | |
| |
| |
Creating Rooms | |
| |
| |
Making the Dungeon Work | |
| |
| |
Summary | |
| |
| |
| |
Projects and Libraries | |
| |
| |
Projects and Using Code from Other Files | |
| |
| |
Basic File Inclusion | |
| |
| |
Inclusions from Other Directories | |
| |
| |
Logic and Including Code | |
| |
| |
Nested Inclusions | |
| |
| |
Libraries | |
| |
| |
The Standard Libraries | |
| |
| |
RubyGems | |
| |
| |
Summary | |
| |
| |
| |
Documentation, Error Handling, Debugging, and Testing | |
| |
| |
Documentation | |
| |
| |
Generating Documentation with RDoc | |
| |
| |
RDoc Techniques | |
| |
| |
Debugging and Errors | |
| |
| |
Exceptions and Error Handling | |
| |
| |
Catch and Throw | |
| |
| |
The Ruby Debugger | |
| |
| |
Testing | |
| |
| |
The Philosophy of Test-Driven Development | |
| |
| |
Unit Testing | |
| |
| |
More Test::Unit Assertions | |
| |
| |
Benchmarking and Profiling | |
| |
| |
Simple Benchmarking | |
| |
| |
Profiling | |
| |
| |
Summary | |
| |
| |
| |
Files and Databases | |
| |
| |
Input and Output | |
| |
| |
Keyboard Input | |
| |
| |
File I/O | |
| |
| |
Basic Databases | |
| |
| |
Text File Databases | |
| |
| |
Storing Objects and Data Structures | |
| |
| |
Relational Databases and SQL | |
| |
| |
Relational Database Concepts | |
| |
| |
The Big Four: MySQL, PostgreSQL, Oracle, and SQLite | |
| |
| |
Installing SQLite | |
| |
| |
A Crash Course in Basic Database Actions and SQL | |
| |
| |
Using SQLite with Ruby | |
| |
| |
Connecting to Other Database Systems | |
| |
| |
ActiveRecord: A Sneak Peek | |
| |
| |
Summary | |
| |
| |
| |
Deploying Ruby Applications and Libraries | |
| |
| |
Distributing Basic Ruby Programs | |
| |
| |
The Shebang Line | |
| |
| |
Associated File Types in Windows | |
| |
| |
"Compiling" Ruby | |
| |
| |
Detecting Ruby's Runtime Environment | |
| |
| |
Easy OS Detection with RUBY_PLATFORM | |
| |
| |
Environment Variables | |
| |
| |
Accessing Command Line Arguments | |
| |
| |
Distributing and Releasing Ruby Libraries As Gems | |
| |
| |
Creating a Gem | |
| |
| |
Distributing a Gem | |
| |
| |
RubyForge | |
| |
| |
Deploying Ruby Applications As Remote Services | |
| |
| |
CGI Scripts | |
| |
| |
Generic HTTP Servers | |
| |
| |
Remote Procedure Calls | |
| |
| |
Summary | |
| |
| |
| |
Advanced Ruby Features | |
| |
| |
Dynamic Code Execution | |
| |
| |
Bindings | |
| |
| |
Other Forms of eval | |
| |
| |
Creating Your Own Version of attr_accessor | |
| |
| |
Running Other Programs from Ruby | |
| |
| |
Getting Results from Other Programs | |
| |
| |
Transferring Execution to Another Program | |
| |
| |
Running Two Programs at the Same Time | |
| |
| |
Interacting with Another Program | |
| |
| |
Safely Handling Data and Dangerous Methods | |
| |
| |
Tainted Data and Objects | |
| |
| |
Safe Levels | |
| |
| |
Working with Microsoft Windows | |
| |
| |
Using the Windows API | |
| |
| |
Controlling Windows Programs | |
| |
| |
Threads | |
| |
| |
Basic Ruby Threads in Action | |
| |
| |
Advanced Thread Operations | |
| |
| |
RubyInline | |
| |
| |
Why Use C As an Inline Language? | |
| |
| |
Creating a Basic Method or Function | |
| |
| |
Benchmarking C vs. Ruby | |
| |
| |
Unicode and UTF-8 Support | |
| |
| |
Summary | |
| |
| |
| |
Tying It Together: Developing a Larger Ruby Application | |
| |
| |
Let's Build a Bot | |
| |
| |
What Is a Bot? | |
| |
| |
Why a Bot? | |
| |
| |
How? | |
| |
| |
Creating a Text Processing Tools Library | |
| |
| |
Building the WordPlay Library | |
| |
| |
Testing the Library | |
| |
| |
Wordplay's Source Code | |
| |
| |
Building the Bot's Core | |
| |
| |
The Program's Life Cycle and Parts | |
| |
| |
Bot Data | |
| |
| |
Constructing the Bot Class and Data Loader | |
| |
| |
The response_to Method | |
| |
| |
Playing with the Bot | |
| |
| |
Main Bot Code Listings | |
| |
| |
Bot.rb | |
| |
| |
Basic_client.rb | |
| |
| |
Extending the Bot | |
| |
| |
Using Text Files As a Source of Conversation | |
| |
| |
Connecting the Bot to the Web | |
| |
| |
Bot-to-Bot Conversations | |
| |
| |
Summary | |
| |
| |
| |
Ruby Online | |
| |
| |
| |
Ruby on Rails: Ruby's Killer App | |
| |
| |
First Steps | |
| |
| |
What Is Rails and Why Use It? | |
| |
| |
Installing Rails | |
| |
| |
Database Considerations | |
| |
| |
Building a Basic Rails Application | |
| |
| |
Creating a Blank Rails Application | |
| |
| |
Database Initialization | |
| |
| |
Creating a Model and Migrations | |
| |
| |
Scaffolding | |
| |
| |
Controllers and Views | |
| |
| |
Routing | |
| |
| |
Model Relationships | |
| |
| |
Sessions and Filters | |
| |
| |
Other Features | |
| |
| |
Layouts | |
| |
| |
Testing | |
| |
| |
Plugins | |
| |
| |
References and Demo Applications | |
| |
| |
Reference Sites and Tutorials | |
| |
| |
Example Rails Applications | |
| |
| |
Summary | |
| |
| |
| |
Ruby and the Internet | |
| |
| |
HTTP and the Web | |
| |
| |
Downloading Web Pages | |
| |
| |
Generating Web Pages and HTML | |
| |
| |
Processing Web Content | |
| |
| |
E-Mail | |
| |
| |
Receiving Mail with POP3 | |
| |
| |
Sending Mail with SMTP | |
| |
| |
Sending Mail with ActionMailer | |
| |
| |
File Transfers with FTP | |
| |
| |
Connection and Basic FTP Actions | |
| |
| |
Downloading Files | |
| |
| |
Uploading Files | |
| |
| |
Summary | |
| |
| |
| |
Networking, Sockets, and Daemons | |
| |
| |
Networking Concepts | |
| |
| |
TCP and UDP | |
| |
| |
IP Addresses and DNS | |
| |
| |
Basic Network Operations | |
| |
| |
Checking Machine and Service Availability | |
| |
| |
Performing DNS Queries | |
| |
| |
Connecting to a TCP Server Directly | |
| |
| |
Servers and Clients | |
| |
| |
UDP Client and Server | |
| |
| |
Building a Simple TCP Server | |
| |
| |
Multi-Client TCP Servers | |
| |
| |
GServer | |
| |
| |
A GServer-Based Chat Server | |
| |
| |
Web/HTTP Servers | |
| |
| |
Daemon Processes | |
| |
| |
Summary | |
| |
| |
| |
Useful Ruby Libraries and Gems | |
| |
| |
Abbrev | |
| |
| |
Installation | |
| |
| |
Examples | |
| |
| |
Further Information | |
| |
| |
Base64 | |
| |
| |
Installation | |
| |
| |
Examples | |
| |
| |
Further Information | |
| |
| |
BlueCloth | |
| |
| |
Installation | |
| |
| |
Examples | |
| |
| |
Further Information | |
| |
| |
Cgi | |
| |
| |
Installation | |
| |
| |
Examples | |
| |
| |
Further Information | |
| |
| |
Chronic | |
| |
| |
Installation | |
| |
| |
Examples | |
| |
| |
Further Information | |
| |
| |
Digest | |
| |
| |
Installation | |
| |
| |
Examples | |
| |
| |
Further Information | |
| |
| |
English | |
| |
| |
Installation | |
| |
| |
Examples | |
| |
| |
Further Information | |
| |
| |
ERB | |
| |
| |
Installation | |
| |
| |
Examples | |
| |
| |
Further Information | |
| |
| |
FasterCSV | |
| |
| |
Installation | |
| |
| |
Examples | |
| |
| |
Further Information | |
| |
| |
Iconv | |
| |
| |
Installation | |
| |
| |
Examples | |
| |
| |
Further Information | |
| |
| |
Logger | |
| |
| |
Installation | |
| |
| |
Examples | |
| |
| |
Further Information | |
| |
| |
Pp | |
| |
| |
Installation | |
| |
| |
Examples | |
| |
| |
Further Information | |
| |
| |
RedCloth | |
| |
| |
Installation | |
| |
| |
Examples | |
| |
| |
Further Information | |
| |
| |
StringScanner | |
| |
| |
Installation | |
| |
| |
Examples | |
| |
| |
Further Information | |
| |
| |
Tempfile | |
| |
| |
Installation | |
| |
| |
Examples | |
| |
| |
Further Information | |
| |
| |
Uri | |
| |
| |
Installation | |
| |
| |
Examples | |
| |
| |
Further Information | |
| |
| |
Zlib | |
| |
| |
Installation | |
| |
| |
Examples | |
| |
| |
Further Information | |
| |
| |
| |
Ruby Primer and Review for Developers | |
| |
| |
The Basics | |
| |
| |
Definition and Concepts | |
| |
| |
The Ruby Interpreter and Running Ruby Code | |
| |
| |
Interactive Ruby | |
| |
| |
Expressions, Logic, and Flow Control | |
| |
| |
Basic Expressions | |
| |
| |
Class Mismatches | |
| |
| |
Comparison Expressions | |
| |
| |
Flow | |
| |
| |
Object Orientation | |
| |
| |
Objects | |
| |
| |
Classes and Methods | |
| |
| |
Reflection | |
| |
| |
Reopening Classes | |
| |
| |
Method Visibility | |
| |
| |
Data | |
| |
| |
Strings | |
| |
| |
Regular Expressions | |
| |
| |
Numbers | |
| |
| |
Arrays | |
| |
| |
Hashes (Associative Arrays) | |
| |
| |
Complex Structures | |
| |
| |
Input/Output | |
| |
| |
Files | |
| |
| |
Databases | |
| |
| |
Web Access | |
| |
| |
Libraries | |
| |
| |
File Organization | |
| |
| |
Packaging | |
| |
| |
| |
Ruby Reference | |
| |
| |
Useful Classes and Methods | |
| |
| |
Array | |
| |
| |
Bignum and Fixnum | |
| |
| |
Enumerable | |
| |
| |
Float | |
| |
| |
Hash | |
| |
| |
Integer | |
| |
| |
Numeric | |
| |
| |
Object | |
| |
| |
String | |
| |
| |
Regular Expression Syntax | |
| |
| |
Regular Expression Options | |
| |
| |
Special Characters and Formations | |
| |
| |
Character and Sub-Expression Suffixes | |
| |
| |
Exception Classes | |
| |
| |
Special Variables | |
| |
| |
Ruby License | |
| |
| |
| |
Useful Resources | |
| |
| |
References | |
| |
| |
Ruby | |
| |
| |
Ruby on Rails | |
| |
| |
Blogs | |
| |
| |
Aggregators and Community Blogs | |
| |
| |
Personal Blogs | |
| |
| |
Forums and Newsgroups | |
| |
| |
Mailing Lists | |
| |
| |
Real-Time Chat | |
| |
| |
Tutorials and Guides | |
| |
| |
Installation | |
| |
| |
Ruby and Techniques | |
| |
| |
Ruby on Rails | |
| |
| |
Other | |
| |
| |
Index | |