Ruby Phrasebook

Book description

Ruby Phrasebook

Jason Clinton

Essential Code and Commands

Ruby Phrasebook gives you the code you need to quickly and effectively work with Ruby, one of the fastest-growing languages in the world thanks to popular new Ruby technologies like Ruby on Rails.

Concise and Accessible

Easy to carry and easy to use—lets you ditch all those bulky books for one portable pocket guide

Flexible and Functional

Packed with more than 100 customizable code snippets—so you can readily code functional Ruby in just about any situation

Jason Clinton uses Ruby daily in system administration and development for Advanced Clustering Technologies, a Linux Beowulf cluster integrator. He has been working in the computer industry for more than a decade and is actively involved in the Kansas City Ruby Users Group (KCRUG), serving as administrator of the group’s web site and mailing list.

Register your book at informit.com/register for convenient access to downloads, updates, and corrections as they become available.

Programming / Ruby

Table of contents

  1. Copyright
  2. About the Author
  3. Acknowledgments
  4. We Want to Hear from You!
  5. Reader Services
  6. Introduction
    1. Audience
    2. How to Use This Book
    3. Conventions
    4. Acknowledgments
      1. Reporting Errata
  7. 1. Converting Between Types
    1. Number from a String
    2. Number to Formatted String
    3. String to Array and Back Again
    4. String to Regular Expression and Back Again
    5. Array to Hash and Back Again
    6. Array to Set and Back Again
    7. Floating-Point, Integer, and Rational Numbers
  8. 2. Working with Strings
    1. Searching Strings
    2. Searching Strings with Regular Expressions
    3. Replacing Substrings
    4. Replacing Substrings using SprintF
    5. Replacing Substrings using Regular Expressions
    6. Working with Unicode
    7. Sanitizing Input
    8. Working with Line Endings
    9. Processing Large Strings
    10. Comparing Strings
    11. Checksumming a String (MD5 or Otherwise)
    12. Encrypting a String
  9. 3. Working with Collections
    1. Slicing an Array
    2. Iterating over an Array
    3. Creating Enumerable Classes
    4. Sorting an Array
    5. Iterating over Nested Arrays
    6. Modifying All the Values in an Array
    7. Sorting Nested Arrays
    8. Building a Hash from a Config File
    9. Sorting a Hash by Key or Value
    10. Eliminating Duplicate Data from Arrays (Sets)
    11. Working with Nested Sets
  10. 4. Working with Objects
    1. Inspecting Objects and Classes
    2. String Presentation of Objects
    3. Ruby-Style Polymorphisms (“Duck Typing”)
    4. Comparing Objects
    5. Serializing Objects
    6. Duplication
    7. Protecting an Object Instance
    8. Garbage Collecting
    9. Using Symbols
  11. 5. Working with Pipes
    1. Determining Interactive Standard Pipes
    2. Synchronizing STDERR with STDOUT
    3. Capturing the Output of a Child Process
    4. Implementing a Progress Bar
    5. Creating a Secured Password Prompt
  12. 6. Working with Files
    1. Opening and Closing Files
    2. Searching and Seeking Large File Contents
    3. When to Use Binary Mode (Win32)
    4. Obtaining an Exclusive Lock
    5. Copying, Moving, and Deleting Files
  13. 7. Manipulating Text
    1. Parsing an LDIF
    2. Parsing a Simple Config File
    3. Interpolating One Text File into Another
    4. Sorting the Contents of a File
    5. Processing a passwd File
  14. 8. Ruby One-Liners
    1. Simple Search
    2. Counting Lines in a File
    3. Head or Tail of a File
    4. MD5 or SHA1 Hash
    5. Simple HTTP Fetch
    6. Simple TCP Connect
    7. Escaping HTML
    8. Deleting Empty Directories
    9. Adding Users from a Text File
    10. Delete All the Files Just Extracted
  15. 9. Processing XML
    1. Opening an XML File
    2. Accessing an Element (Node)
    3. Getting a List of Attributes
    4. Adding an Element
    5. Changing an Element’s Enclosed Text
    6. Deleting an Element
    7. Adding an Attribute
    8. Changing an Attribute
    9. Deleting an Attribute
    10. Escaping Characters for XML
    11. Transforming Using XSLT
    12. Validating Your XML
    13. A Simple RSS Parser
  16. 10. Rapid Applications Development with GUI Toolkits
    1. A Simple GTK+ Hello World
    2. Using Glade
    3. A Simple Qt Hello World
    4. Attaching a Signal Handler to a Qt Widget Slot
    5. Using Qt Designer
    6. Attaching Signal Handers to Qt Designer Generated Code
  17. 11. Simple CGI Forms
    1. Processing a Web Form
    2. Returning Tabled Results
    3. Escaping Input
    4. Locking Down Ruby
    5. Receiving an Uploaded File
    6. Representing Data Graphically
  18. 12. Connecting to Databases
    1. Opening (and Closing) a MySQL Database Connection
    2. Creating a Table
    3. Getting a List of Tables
    4. Adding Rows to a Table
    5. Iterating Over Queried Rows
    6. Deleting Rows
    7. Deleting a Table
  19. 13. Working with Networking and Sockets
    1. Connecting to a TCP Socket
    2. Running a TCP Server on a Socket
    3. Serializing Objects with YAML
    4. Network Objects with Distributed Ruby
    5. Using Net::HTTP
    6. Using Webrick
  20. 14. Working with Threads
  21. 15. Documenting Your Ruby
    1. Documenting Ruby Code
    2. Typographic Conventions Used
    3. Overriding Method Signatures in Documentation
    4. Hiding a Module, Class, or Method
    5. Providing Program Usage Help
    6. Generating HTML Documentation
    7. Generating and Installing Documentation for ri
  22. 16. Working with Ruby Packages
    1. Installing a Module
    2. Removing a Module
    3. Searching for a Module
    4. Updating Modules
    5. Examining a Module
    6. Packaging Your Module with Hoe
    7. Creating a Simple Test Case
    8. Distributing Your Module on RubyForge
    9. Making Rakefile Standalone

Product information

  • Title: Ruby Phrasebook
  • Author(s):
  • Release date: August 2008
  • Publisher(s): Addison-Wesley Professional
  • ISBN: 9780672328978