You are previewing Ruby in a Nutshell.
O'Reilly logo
Ruby in a Nutshell

Book Description

Ruby is an absolutely pure object-oriented scripting language written in C and designed with Perl and Python capabilities in mind. While its roots are in Japan, Ruby is slowly but surely gaining ground in the US. The goal of Yukihiro Matsumoto, creator of Ruby and author of this book, is to incorporate the strengths of languages like Perl, Python, Lisp and Smalltalk. Ruby is a genuine attempt to combine the best of everything in the scripting world. Since 1993, Ruby mailing lists have been established, Web pages have formed, and a community has grown around it. The language itself is very good at text processing and is notable for its broad object orientation. Ruby is portable and runs under GNU/Linux (and other Unices) as well as DOS, MS Windows and Mac. With Ruby in a Nutshell, Matsumoto offers a practical reference to the features of this new language including the command-line options, syntax, built-in variables, functions, and many commonly used classes and modules. This guide covers the current stable version of Ruby (1.6), yet is applicable to the development version 1.7 and the next planned stable version 1.8. You will find a thorough description of Ruby's language syntax, and a description of the core functionality built into the standard Ruby interpreter, which has more than 800 built-in methods in 42 classes and modules. Ruby finds its power through its built-in libraries, and this handy volume take you through the many useful libraries that come with the standard Ruby distribution--from network access via HTTP and CGI programming, to data persistence using the DBM library. This book concludes with coverage of the unique tools that come with Ruby, including the debugger, profiler, and irb (or interactive ruby.) Find out how Ruby combines the strengths of other languages, and why it has captured the interest of so many open source programmers. As part of the successful "in a nutshell" series of books from O'Reilly & Associates, Ruby in a Nutshell is for readers who want a single desktop reference for all their needs.

Table of Contents

  1. Ruby in a Nutshell
    1. SPECIAL OFFER: Upgrade this ebook with O’Reilly
    2. Foreword
    3. Preface
      1. How This Book Is Organized
      2. Conventions Used in This Book
      3. Comments and Questions
      4. Acknowledgments
    4. 1. Introduction
      1. 1.1. Ruby's Elegance
      2. 1.2. Ruby in Action
    5. 2. Language Basics
      1. 2.1. Command-Line Options
      2. 2.2. Environment Variables
      3. 2.3. Lexical Conventions
        1. 2.3.1. Whitespace
        2. 2.3.2. Line Endings
        3. 2.3.3. Comments
        4. 2.3.4. Identifiers
        5. 2.3.5. Reserved Words
      4. 2.4. Literals
        1. 2.4.1. Numbers
          1. 2.4.1.1. Integers
          2. 2.4.1.2. Floating-point numbers
        2. 2.4.2. Strings
          1. 2.4.2.1. String concatenation
          2. 2.4.2.2. Expression substitution
          3. 2.4.2.3. Backslash notation
          4. 2.4.2.4. General delimited strings
          5. 2.4.2.5. here documents
        3. 2.4.3. Symbols
        4. 2.4.4. Arrays
          1. 2.4.4.1. General delimited string array
        5. 2.4.5. Hashes
        6. 2.4.6. Regular Expressions
          1. 2.4.6.1. Regular-expression modifiers
          2. 2.4.6.2. Regular-expression patterns
      5. 2.5. Variables
        1. Global Variables
        2. Instance Variables
        3. Class Variables
        4. Local Variables
        5. Constants
        6. Pseudo-Variables
        7. Assignment
        8. Parallel Assignment
        9. Abbreviated Assignment
      6. 2.6. Operators
        1. 2.6.1. Operator Expressions
          1. 2.6.1.1. Nonmethod operators
          2. 2.6.1.2. Range operators
          3. 2.6.1.3. Logical operators
          4. 2.6.1.4. Ternary operator
          5. 2.6.1.5. defined? operator
      7. 2.7. Methods
        1. Reference Section
          1. Normal Method Calls
        2. 2.7.1. Specifying Blocks with Method Calls
          1. def Statement
        3. 2.7.2. Singleton Methods
          1. def Statement for Singleton Methods
        4. 2.7.3. Method Operations
          1. alias Statement
          2. undef Statement
        5. 2.7.4. Other Method-Related Statements
          1. yield Statement
          2. super Statement
      8. 2.8. Control Structures
        1. if Statement
        2. unless Statement
        3. case Statement
        4. while Statement
        5. until Statement
        6. for Statement
        7. break Statement
        8. next Statement
        9. redo Statement
        10. retry Statement
        11. begin Statement
        12. rescue Statement
        13. raise method
        14. BEGIN Statement
        15. END Statement
      9. 2.9. Object-Oriented Programming
        1. 2.9.1. Classes and Instances
          1. class Statement
        2. 2.9.2. Methods
        3. 2.9.3. Singleton Classes
        4. 2.9.4. Modules
          1. module Statement
        5. 2.9.5. Mix-ins
        6. 2.9.6. Method Visibility
        7. 2.9.7. Object Initialization
        8. 2.9.8. Attributes
        9. 2.9.9. Hooks
      10. 2.10. Security
        1. 2.10.1. Restricted Execution
          1. Level 0
          2. Level 1
          3. Level 2
          4. Level 3
          5. Level 4
    6. 3. Built-in Library Reference
      1. 3.1. Predefined Variables
      2. 3.2. Predefined Global Constants
      3. 3.3. Built-in Functions
      4. 3.4. Built-in Library
        1. 3.4.1. Objects
          1. Object
          2. Kernel
        2. 3.4.2. Strings and Regular Expressions
          1. String
          2. Regexp
          3. MatchData
        3. 3.4.3. Arrays and Hashes
          1. Array
          2. Hash
          3. Enumerable
        4. 3.4.4. Numbers
          1. Numeric
          2. Integer
          3. Fixnum
          4. Bignum
          5. Float
          6. Precision
          7. Comparable
          8. Math
        5. 3.4.5. Operating System Services
          1. IO
          2. File
          3. File::Stat
          4. FileTest
          5. Dir
          6. Process
        6. 3.4.6. Threads
          1. Thread
          2. ThreadGroup
        7. 3.4.7. Exceptions
          1. Exception
          2. Errno
        8. 3.4.8. Built-in Exceptions
        9. 3.4.9. Classes and Modules
          1. Module
          2. Class
        10. 3.4.10. Proc Objects and Bindings
          1. Proc
          2. Method
          3. UnboundMethod
          4. Binding
          5. Continuation
        11. 3.4.11. Miscellaneous Classes and Modules
          1. GC
          2. ObjectSpace
          3. NilClass
          4. TrueClass
          5. FalseClass
          6. Data
          7. Marshal
          8. Range
          9. Struct
          10. Time
    7. 4. Standard Library Reference
      1. 4.1. Standard Library
        1. 4.1.1. Network
          1. BasicSocket
          2. IPSocket
          3. UDPSocket
          4. TCPSocket
          5. TCPServer
          6. UNIXSocket
          7. UNIXServer
          8. Socket
          9. Net::FTP
          10. Net::HTTP
          11. Net::IMAP
          12. Net::POP3
          13. Net::APOP
          14. Net::POPMail
          15. Net::SMTP
          16. Net::Telnet
          17. CGI
          18. CGI::Cookie
          19. CGI::Session
        2. 4.1.2. Operating System Services
          1. Curses
          2. Curses::Window
          3. Etc
          4. Fcntl
          5. Find
          6. ftools
          7. GetoptLong
          8. PTY
          9. Readline
          10. Tempfile
          11. Win32API
        3. 4.1.3. Threads
          1. ConditionVariable
          2. Monitor
          3. MonitorMixin
          4. Mutex
          5. Queue
          6. SizedQueue
          7. ThreadsWait
        4. 4.1.4. Data Persistence
          1. DBM
          2. GDBM
          3. SDBM
          4. PStore
        5. 4.1.5. Numbers
          1. Complex
          2. Rational
          3. Matrix
        6. 4.1.6. Design Patterns
          1. Delegator
          2. SimpleDelegator
          3. DelegatorClass
          4. Forwardable
          5. SingleForwardable
          6. Singleton
          7. Observable
        7. 4.1.7. Miscellaneous Libraries
          1. Date
          2. ParseDate
          3. timeout
          4. MD5
          5. SHA1
    8. 5. Ruby Tools
      1. 5.1. Standard Tools
        1. 5.1.1. Debugger
        2. 5.1.2. Profiler
        3. 5.1.3. Tracer
        4. 5.1.4. irb
        5. 5.1.5. ruby-mode for Emacs
      2. 5.2. Additional Tools
        1. 5.2.1. ri: Ruby Interactive Reference
        2. 5.2.2. eRuby
      3. 5.3. Ruby Application Archive
    9. 6. Ruby Updates
      1. 6.1. Summary of Changes
      2. 6.2. Changes from 1.6.5 to 1.7.1
      3. 6.3. The Future of Ruby
      4. 6.4. Participate in Ruby
    10. Index
    11. About the Author
    12. Colophon
    13. SPECIAL OFFER: Upgrade this ebook with O’Reilly