Synopses & Reviews
You don't have to know everything about a car to drive one, and you don't need to know everything about Ruby to start programming with it. Written for both experienced and new programmers alike, Learning Ruby is a just-get-in-and-drive book -- a hands-on tutorial that offers lots of Ruby programs and lets you know how and why they work, just enough to get you rolling down the road.
Interest in Ruby stems from the popularity of Rails, the web development framework that's attracting new devotees and refugees from Java and PHP. But there are plenty of other uses for this versatile language. The best way to learn is to just try the code! You'll find examples on nearly every page of this book that you can imitate and hack. Briefly, this book:
- Outlines many of the most important features of Ruby
- Demonstrates how to use conditionals, and how to manipulate strings in Ruby. Includes a section on regular expressions
- Describes how to use operators, basic math, functions from the Math module, rational numbers, etc.
- Talks you through Ruby arrays, and demonstrates hashes in detail
- Explains how to process files with Ruby
- Discusses Ruby classes and modules (mixins) in detail, including a brief introduction to object-oriented programming (OOP)
- Introduces processing XML, the Tk toolkit, RubyGems, reflection, RDoc, embedded Ruby, metaprogramming, exception handling, and other topics
- Acquaints you with some of the essentials of Rails, and includes a short Rails tutorial.
Each chapter concludes with a set of review questions, and appendices provide you with a glossary of terms related to Ruby programming, plus reference material from the book in one convenient location. If you want to take Ruby out for a drive,
Learning Ruby holds the keys.
About the Author
Michael Fitzgerald is Principal at Overdue Books LLC, a publishing and writing firm. He is the author of Learning Ruby, Ruby Pocket Reference, XML Pocket Reference, Third Edition with Simon St. Laurent, XML Hacks, and Learning XSLT, all published by O'Reilly. He is also the author of Building B2B Applications with XML: A Resource Guide and XSL Essentials (both by John Wiley & Sons). His books have been translated into Spanish, French, German, Japanese, and Chinese. He has also been a regular contributor to XML.com. Michael likes to ski (downhill and cross country), ride and train horses, and spend time with his family.
Table of Contents
Dedication; Preface; Who Should Read This Book?; How This Book Works; About the Examples; How This Book Is Organized; Conventions Used in This Book; Comments and Questions; Safari® Enabled; Acknowledgments; Chapter 1: Ruby Basics; 1.1 Hello, Matz; 1.2 Interactive Ruby; 1.3 Resources; 1.4 Installing Ruby; 1.5 Permission Denied; 1.6 Associating File Types on Windows; 1.7 Review Questions; Chapter 2: A Quick Tour of Ruby; 2.1 Ruby Is Object-Oriented; 2.2 Ruby's Reserved Words; 2.3 Comments; 2.4 Variables; 2.5 Strings; 2.6 Numbers and Operators; 2.7 Conditional Statements; 2.8 Arrays and Hashes; 2.9 Methods; 2.10 Blocks; 2.11 Symbols; 2.12 Exception Handling; 2.13 Ruby Documentation; 2.14 Review Questions; Chapter 3: Conditional Love; 3.1 The if Statement; 3.2 The case Statement; 3.3 The while Loop; 3.4 The loop Method; 3.5 The for loop; 3.6 Execution Before or After a Program; 3.7 Review Questions; Chapter 4: Strings; 4.1 Creating Strings; 4.2 Concatenating Strings; 4.3 Accessing Strings; 4.4 Comparing Strings; 4.5 Manipulating Strings; 4.6 Case Conversion; 4.7 Managing Whitespace, etc.; 4.8 Incrementing Strings; 4.9 Converting Strings; 4.10 Regular Expressions; 4.11 1.9 and Beyond; 4.12 Review Questions; Chapter 5: Math; 5.1 Class Hierarchy and Included Modules; 5.2 Converting Numbers; 5.3 Basic Math Operations; 5.4 Ranges; 5.5 Inquiring About Numbers; 5.6 More Math Methods; 5.7 Math Functions; 5.8 Rational Numbers; 5.9 Prime Numbers; 5.10 Review Questions; Chapter 6: Arrays; 6.1 Creating Arrays; 6.2 Accessing Elements; 6.3 Concatenation; 6.4 Set Operations; 6.5 Unique Elements; 6.6 Blow Your Stack; 6.7 Comparing Arrays; 6.8 Changing Elements; 6.9 Deleting Elements; 6.10 Arrays and Blocks; 6.11 Sorting Things and About Face; 6.12 Multidimensional Arrays; 6.13 1.9 and Beyond; 6.14 Other Array Methods; 6.15 Review Questions; Chapter 7: Hashes; 7.1 Creating Hashes; 7.2 Accessing Hashes; 7.3 Iterating over Hashes; 7.4 Changing Hashes; 7.5 Converting Hashes to Other Classes; 7.6 1.9 and Beyond; 7.7 Other Hash Methods; 7.8 Review Questions; Chapter 8: Working with Files; 8.1 Directories; 8.2 Creating a New File; 8.3 Opening an Existing File; 8.4 Deleting and Renaming Files; 8.5 File Inquiries; 8.6 Changing File Modes and Owner; 8.7 The IO Class; 8.8 Review Questions; Chapter 9: Classes; 9.1 Defining the Class; 9.2 Instance Variables; 9.3 Accessors; 9.4 Class Variables; 9.5 Class Methods; 9.6 Inheritance; 9.7 Modules; 9.8 public, private, or protected; 9.9 Review Questions; Chapter 10: More Fun with Ruby; 10.1 Formatting Output with sprintf; 10.2 Processing XML; 10.3 Date and Time; 10.4 Reflection; 10.5 Using Tk; 10.6 Metaprogramming; 10.7 RubyGems; 10.8 Exception Handling; 10.9 Creating Documentation with RDoc; 10.10 Embedded Ruby; 10.11 Review Questions; Chapter 11: A Short Guide to Ruby on Rails; 11.1 Where Did Rails Come From; 11.2 Why Rails?; 11.3 What Have Other Folks Done with Rails?; 11.4 Hosting Rails; 11.5 Installing Rails; 11.6 Learning Rails; 11.7 A Brief Tutorial; 11.8 Review Questions; Ruby Reference; Ruby Interpreter; Ruby's Reserved Words; Operators; Escape Characters; Predefined Variables; Global Constants; Regular Expressions; String Unpack Directives; Array Pack Directives; Sprintf Flags and Field Types; File Tests; Time Formatting Directives; RDoc Options; Rake; Answers to Review Questions; Chapter 1 Review Questions; Chapter 2 Review Questions; Chapter 3 Review Questions; Chapter 4 Review Questions; Chapter 5 Review Questions; Chapter 6 Review Questions; Chapter 7 Review Questions; Chapter 8 Review Questions; Chapter 9 Review Questions; Chapter 10 Review Questions; Chapter 11 Review Questions; Glossary; Colophon;