Dedication;Preface; Life Is Short; Audience; The Structure of This Book; How the Code Listings Work; Installing the Software; Platform Differences, Version Differences, and Other Headaches; Other Resources; Conventions Used in This Book; Using Code Examples; Comments and Questions; Acknowledgments;Chapter 1: Strings; 1.1 Building a String from Parts; 1.2 Substituting Variables into Strings; 1.3 Substituting Variables into an Existing String; 1.4 Reversing a String by Words or Characters; 1.5 Representing Unprintable Characters; 1.6 Converting Between Characters and Values; 1.7 Converting Between Strings and Symbols; 1.
8 Processing a String One Character at a Time; 1.9 Processing a String One Word at a Time; 1.10 Changing the Case of a String; 1.11 Managing Whitespace; 1.12 Testing Whether an Object Is String-Like; 1.13 Getting the Parts of a String You Want; 1.14 Handling International Encodings; 1.15 Word-Wrapping Lines of Text; 1.
16 Generating a Succession of Strings; 1.17 Matching Strings with Regular Expressions; 1.18 Replacing Multiple Patterns in a Single Pass; 1.19 Validating an Email Address; 1.20 Classifying Text with a Bayesian Analyzer;Chapter 2: Numbers; 2.1 Parsing a Number from a String; 2.2 Comparing Floating-Point Numbers; 2.3 Representing Numbers to Arbitrary Precision; 2.
4 Representing Rational Numbers; 2.5 Generating Random Numbers; 2.6 Converting Between Numeric Bases; 2.7 Taking Logarithms; 2.8 Finding Mean, Median, and Mode; 2.9 Converting Between Degrees and Radians; 2.10 Multiplying Matrices; 2.11 Solving a System of Linear Equations; 2.
12 Using Complex Numbers; 2.13 Simulating a Subclass of Fixnum; 2.14 Doing Math with Roman Numbers; 2.15 Generating a Sequence of Numbers; 2.16 Generating Prime Numbers; 2.17 Checking a Credit Card CheckâChapter 3: Date and Time; 3.1 Finding Today''s Date; 3.2 Parsing Dates, Precisely or Fuzzily; 3.
3 Printing a Date; 3.4 Iterating Over Dates; 3.5 Doing Date Arithmetic; 3.6 Counting the Days Since an Arbitrary Date; 3.7 Converting Between Time Zones; 3.8 Checking Whether Daylight Saving Time Is in Effect; 3.9 Converting Between Time and DateTime Objects; 3.10 Finding the Day of the Week; 3.
11 Handling Commercial Dates; 3.12 Running a Code Block Periodically; 3.13 Waiting a Certain Amount of Time; 3.14 Adding a Timeout to a Long-Running Operation;Chapter 4: Arrays; 4.1 Iterating Over an Array; 4.2 Rearranging Values Without Using Temporary Variables; 4.3 Stripping Duplicate Elements from an Array; 4.4 Reversing an Array; 4.
5 Sorting an Array; 4.6 Ignoring Case When Sorting Strings; 4.7 Making Sure a Sorted Array Stays Sorted; 4.8 Summing the Items of an Array; 4.9 Sorting an Array by Frequency of Appearance; 4.10 Shuffling an Array; 4.11 Getting the N Smallest Items of an Array; 4.12 Building Up a Hash Using Injection; 4.
13 Extracting Portions of Arrays; 4.14 Computing Set Operations on Arrays; 4.15 Partitioning or Classifying a Set;Chapter 5: Hashes; 5.1 Using Symbols as Hash Keys; 5.2 Creating a Hash with a Default Value; 5.3 Adding Elements to a Hash; 5.4 Removing Elements from a Hash; 5.5 Using an Array or Other Modifiable Object as a Hash Key; 5.
6 Keeping Multiple Values for the Same Hash Key; 5.7 Iterating Over a Hash; 5.8 Iterating Over a Hash in Insertion Order; 5.9 Printing a Hash; 5.10 Inverting a Hash; 5.11 Choosing Randomly from a Weighted List; 5.12 Building a Histogram; 5.13 Remapping the Keys and Values of a Hash; 5.
14 Extracting Portions of Hashes; 5.15 Searching a Hash with Regular Expressions;Chapter 6: Files and Directories; 6.1 Checking to See If a File Exists; 6.2 Checking Your Access to a Fi⤠6.3 Changing the Permissions on a Fi⤠6.4 Seeing When a File Was Last Used Problem; 6.5 Listing a Directory; 6.6 Reading the Contents of a Fi⤠6.
7 Writing to a Fi⤠6.8 Writing to a Temporary Fi⤠6.9 Picking a Random Line from a Fi⤠6.10 Comparing Two Files; 6.11 Performing Random Access on "Read-Once" Input Streams; 6.12 Walking a Directory Tree; 6.13 Locking a Fi⤠6.14 Backing Up to Versioned Filenames; 6.
15 Pretending a String Is a Fi⤠6.16 Redirecting Standard Input or Output; 6.17 Processing a Binary Fi⤠6.18 Deleting a Fi⤠6.19 Truncating a Fi⤠6.20 Finding the Files You Want; 6.21 Finding and Changing the Current Working Directory;Chapter 7: Code Blocks and Iteration; 7.1 Creating and Invoking a Block; 7.
2 Writing a Method That Accepts a Block; 7.3 Binding a Block Argument to a Variab⤠7.4 Blocks as Closures: Using Outside Variables Within a Code Block; 7.5 Writing an Iterator Over a Data Structure; 7.6 Changing the Way an Object Iterates; 7.7 Writing Block Methods That Classify or Collect; 7.8 Stopping an Iteration; 7.9 Looping Through Multiple Iterables in Parallel; 7.
10 Hiding Setup and Cleanup in a Block Method; 7.11 Coupling Systems Loosely with Callbacks;Chapter 8: Objects and Classes; 8.1 Managing Instance Data; 8.2 Managing Class Data; 8.3 Checking Class or Module Membership; 8.4 Writing an Inherited Class; 8.5 Overloading Methods; 8.6 Validating and Modifying Attribute Values; 8.
7 Defining a Virtual Attribute; 8.8 Delegating Method Calls to Another Object; 8.9 Converting and Coercing Objects to Different Types; 8.10 Getting a Human-Readable Printout of Any Object; 8.11 Accepting or Passing a Variable Number of Arguments; 8.12 Simulating Keyword Arguments; 8.13 Calling a Superclass''s Method; 8.14 Creating an Abstract Method; 8.
15 Freezing an Object to Prevent Changes; 8.16 Making a Copy of an Object; 8.17 Declaring Constants; 8.18 Implementing Class and Singleton Methods; 8.19 Controlling Access by Making Methods Private;Chapter 9: Modules and Namespaces; 9.1 Simulating Multiple Inheritance with Mixins; 9.2 Extending Specific Objects with Modules; 9.3 Mixing in Class Methods; 9.
4 Implementing Enumerable: Write One Method, Get 22 Free; 9.5 Avoiding Naming Collisions with Namespaces; 9.6 Automatically Loading Libraries as Needed; 9.7 Including Namespaces; 9.8 Initializing Instance Variables Defined by a Modu⤠9.9 Automatically Initializing Mixed-In Modules;Chapter 10: Reflection and Metaprogramming; 10.1 Finding an Object''s Class and Superclass; 10.2 Listing an Object''s Methods; 10.
3 Listing Methods Unique to an Object; 10.4 Getting a Reference to a Method; 10.5 Fixing Bugs in Someone Else''s Class; 10.6 Listening for Changes to a Class; 10.7 Checking Whether an Object Has Necessary Attributes; 10.8 Responding to Calls to Undefined Methods; 10.9 Automatically Initializing Instance Variables; 10.10 Avoiding Boilerplate Code with Metaprogramming; 10.
11 Metaprogramming with String Evaluations; 10.12 Evaluating Code in an Earlier Context; 10.13 Undefining a Method; 10.14 Aliasing Methods; 10.15 Doing Aspect-Oriented Programming; 10.16 Enforcing Software Contracts;Chapter 11: XML and HTML; 11.1 Checking XML Well-Formedness; 11.2 Extracting Data from a Document''s Tree Structure; 11.
3 Extracting Data While Parsing a Document; 11.4 Navigating a Document with XPath; 11.5 Parsing Invalid Markup; 11.6 Converting an XML Document into a Hash; 11.7 Validating an XML Document; 11.8 Substituting XML Entities; 11.9 Creating and Modifying XML Documents; 11.10 Compressing Whitespace in an XML Document; 11.
11 Guessing a Document''s Encoding; 11.12 Converting from One Encoding to Another; 11.13 Extracting All the URLs from an HTML Document; 11.14 Transforming Plain Text to HTML; 11.15 Converting HTML Documents from the Web into Text; 11.16 A Simple Feed Aggregatâ¨Chapter 12: Graphics and Other File Formats; 12.1 Thumbnailing Images; 12.2 Adding Text to an â 12.
3 Converting One Image Format to Another; 12.4 Graphing Data; 12.5 Adding Graphical Context with Sparklines; 12.6 Strongly Encrypting Data; 12.7 Parsing Comma-Separated Data; 12.8 Parsing Not-Quite-Comma-Separated Data; 12.9 Generating and Parsing Excel Spreadsheets; 12.10 Compressing and Archiving Files with Gzip and Tar; 12.
11 Reading and Writing ZIP Files; 12.12 Reading and Writing Configuration Files; 12.13 Generating PDF Files; 12.14 Representing Data as MIDI Music;Chapter 13: Databases and Persistence; 13.1 Serializing Data with YAML; 13.2 Serializing Data with Marshal; 13.3 Persisting Objects with Madeleiâ 13.4 Indexing Unstructured Text with SimpleSearch; 13.
5 Indexing Structured Text with Ferret; 13.6 Using Berkeley DB Databases; 13.7 Controlling MySQL on Unix; 13.8 Finding the Number of Rows Returned by a Query; 13.9 Talking Directly to a MySQL Database; 13.10 Talking Directly to a PostgreSQL Database; 13.11 Using Object Relational Mapping with ActiveRecord; 13.12 Using Object Relational Mapping with Og; 13.
13 Building Queries Programmatically; 13.14 Validating Data with ActiveRecord; 13.15 Preventing SQL Injection Attacks; 13.16 Using Transactions in ActiveRecord; 13.17 Adding Hooks to Table Events; 13.18 Adding Taggability with a Database Mixin;Chapter 14: Internet Services; 14.1 Grabbing the Contents of a Web Pa⥠14.2 Making an HTTPS Web Request; 14.
3 Customizing HTTP Request Headers; 14.4 Performing DNS Queries; 14.5 Sending Mail; 14.6 Reading Mail with IMAP; 14.7 Reading Mail with POP3; 14.8 Being an FTP Client; 14.9 Being a Telnet Client; 14.10 Being an SSH Client; 14.
11 Copying a File to Another Machiâ 14.12 Being a BitTorrent Client; 14.13 Pinging a Machiâ 14.14 Writing an Internet Server; 14.15 Parsing URLs; 14.16 Writing a CGI Script; 14.17 Setting Cookies and Other HTTP Response Headers; 14.18 Handling File Uploads via CGI; 14.
19 Running Servlets with WEBrick; 14.20 A Real-World HTTP Client;Chapter 15: Web Development: Ruby on Rails; 15.1 Writing a Simple Rails Application to Show System Status; 15.2 Passing Data from the Controller to the View; 15.3 Creating a Layout for Your Header and Footer; 15.4 Redirecting to a Different Location; 15.5 Displaying Templates with Render; 15.6 Integrating a Database with Your Rails Application; 15.
7 Understanding Pluralization Rules; 15.8 Creating a Login System; 15.9 Storing Hashed User Passwo.