The Book of Ruby

Book description

Slice your way through the cruft of programming conventions and learn to blaze your own trail with The Book of Ruby. From methods to metaprogramming, you'll gain the skills you need to master the world's most fun programming language with this example-based, hands-on introduction.

Table of contents

  1. The Book of Ruby
    1. Acknowledgments
    2. Introduction
      1. What Is Ruby?
      2. What Is Rails?
      3. Matters of Ruby Style
      4. How to Read This Book
      5. Digging Deeper
      6. Making Sense of the Text
      7. Downloading Ruby
      8. Getting the Source Code of the Sample Programs
      9. Running Ruby Programs
      10. The Ruby Library Documentation
    3. 1. Strings, Numbers, Classes, and Objects
      1. Getting and Putting Input
      2. Strings and Embedded Evaluation
      3. Numbers
      4. Comments
      5. Testing a Condition: if..then
      6. Local and Global Variables
      7. Classes and Objects
        1. Instance Variables
        2. Retrieving Data from an Object
        3. Messages, Methods, and Polymorphism
        4. Constructors: new and initialize
        5. Inspecting Objects
    4. 2. Class Hierarchies, Attributes, and Class Variables
      1. Superclasses and Subclasses
      2. Passing Arguments to the Superclass
      3. Accessor Methods
      4. Attribute Readers and Writers
      5. Calling Methods of a Superclass
      6. Class Variables
    5. 3. Strings and Ranges
      1. User-Defined String Delimiters
      2. Backquotes
      3. String Handling
        1. Concatenation
        2. What About Commas?
        3. String Assignment
        4. Indexing into a String
        5. Removing Newline Characters: chop and chomp
        6. Format Strings
      4. Ranges
        1. Ranges of Strings
        2. Iterating with a Range
    6. 4. Arrays and Hashes
      1. Arrays
        1. Creating Arrays
        2. Multidimensional Arrays
        3. Iterating over Arrays
        4. Indexing into Arrays
        5. Copying Arrays
        6. Testing Arrays for Equality
        7. Sorting Arrays
        8. Comparing Values
        9. Array Methods
      2. Hashes
        1. Creating Hashes
        2. Indexing into a Hash
        3. Copying a Hash
        4. Hash Order
        5. Sorting a Hash
        6. Hash Methods
    7. 5. Loops and Iterators
      1. for Loops
      2. Blocks and Block Parameters
      3. Iterating upto and downto
      4. Multiple Iterator Arguments
      5. while Loops
        1. while Modifiers
        2. Ensuring a while Loop Executes at Least Once
      6. until Loops
      7. loop
    8. 6. Conditional Statements
      1. if..then..else
      2. and, or, and not
      3. Negation
      4. if..elsif
      5. unless
      6. if and unless Modifiers
      7. Case Statements
        1. The === Method
        2. Alternative Case Syntax
    9. 7. Methods
      1. Class Methods
      2. What Are Class Methods For?
      3. Class Variables
      4. Ruby Constructors: new or initialize?
      5. Singleton Methods
      6. Singleton Classes
      7. Overriding Methods
      8. Public, Protected, and Private Methods
    10. 8. Passing Arguments and Returning Values
      1. Summarizing Instance, Class, and Singleton Methods
      2. Returning Values
      3. Returning Multiple Values
      4. Default and Multiple Arguments
      5. Assignment and Parameter Passing
      6. Integers Are Special
      7. The One-Way-In, One-Way-Out Principle
      8. Modifying Receivers and Yielding New Objects
      9. Potential Side Effects of Reliance on Argument Values
      10. Parallel Assignment
    11. 9. Exception Handling
      1. rescue: Execute Code When Error Occurs
      2. ensure: Execute Code Whether or Not an Error Occurs
      3. else: Execute Code When No Error Occurs
      4. Error Numbers
      5. retry: Attempt to Execute Code Again After an Error
      6. raise: Reactivate a Handled Error
    12. 10. Blocks, Procs, and Lambdas
      1. What Is a Block?
      2. Line Breaks Are Significant
      3. Nameless Functions
      4. Look Familiar?
      5. Blocks and Arrays
      6. Procs and Lambdas
      7. Block or Hash?
      8. Creating Objects from Blocks
      9. What Is a Closure?
      10. yield
      11. Blocks Within Blocks
      12. Passing Named Proc Arguments
      13. Precedence Rules
      14. Blocks as Iterators
    13. 11. Symbols
      1. Symbols and Strings
      2. Symbols and Variables
      3. Why Use Symbols?
    14. 12. Modules and Mixins
      1. A Module Is Like a Class . . .
      2. Module Methods
      3. Modules as Namespaces
      4. Included Modules, or “Mixins”
      5. Name Conflicts
      6. Alias Methods
      7. Mix In with Care!
      8. Including Modules from Files
    15. 13. Files and IO
      1. Opening and Closing Files
      2. Characters and Compatibility
      3. Files and Directories
      4. Copying Files
      5. Directory Inquiries
      6. A Discursion into Recursion
      7. Sorting by Size
    16. 14. YAML
      1. Converting to YAML
      2. Nested Sequences
      3. Saving YAML Data
      4. Omitting Variables on Saving
      5. Multiple Documents, One File
      6. A YAML Database
      7. Adventures in YAML
    17. 15. Marshal
      1. Saving and Loading Data
      2. Omitting Variables on Saving
      3. Saving Singletons
        1. YAML and Singletons
        2. Marshal and Singletons
    18. 16. Regular Expressions
      1. Making Matches
      2. Match Groups
      3. MatchData
      4. Prematch and Postmatch
      5. Greedy Matching
      6. String Methods
      7. File Operations
    19. 17. Threads
      1. Creating Threads
      2. Running Threads
      3. Going Native
      4. The Main Thread
      5. Thread Status
      6. Ensuring That a Thread Executes
      7. Thread Priorities
      8. The Main Thread Priority
      9. Mutexes
      10. Fibers
    20. 18. Debugging and Testing
      1. IRB: Interactive Ruby
      2. Debugging
      3. Unit Testing
    21. 19. Ruby on Rails
      1. Installing Rails
        1. Do It Yourself . . .
        2. Or Use an “All-in-One” Installer
      2. Model-View-Controller
      3. A First Ruby on Rails Application
      4. Create a Rails Application
      5. Create a Controller
      6. Anatomy of a Simple Rails Application
      7. The Generate Controller Script Summarized
      8. Create a View
      9. Rails Tags
      10. Let’s Make a Blog!
        1. Create the Database
        2. Creating a MySQL Database
        3. Scaffolding
        4. Migration
        5. Partials
        6. Test It!
    22. 20. Dynamic Programming
      1. Self-Modifying Programs
      2. eval
      3. Special Types of eval
      4. Adding Variables and Methods
      5. Creating Classes at Runtime
      6. Bindings
      7. send
      8. Removing Methods
      9. Handling Missing Methods
      10. Writing Programs at Runtime
      11. Exploring Further
    23. A. Documenting Ruby with RDoc
    24. B. Installing MySQL for Ruby on Rails
      1. Downloading MySQL
      2. Installing MySQL
      3. Configuring MySQL
      4. Can’t Find the Database?
    25. C. Further Reading
      1. Books
      2. Ebooks
      3. Websites
    26. D. Ruby and Rails Development Software
      1. IDEs and Editors
      2. Web Servers
      3. Databases
      4. Ruby Implementations
    27. Index
    28. About the Author
    29. Colophon
    30. E. Updates

Product information

  • Title: The Book of Ruby
  • Author(s):
  • Release date: July 2011
  • Publisher(s): No Starch Press
  • ISBN: 9781593272944