Synopses & Reviews
Ruby is famous for being easy to learn, but most users only scratch the surface of what it can do. While other books focus on Ruby's trendier features, The Book of Ruby reveals the secret inner workings of one of the world's most popular programming languages, teaching you to write clear, maintainable code.
You'll start with the basics—types, data structures, and control flows—and progress to advanced features like blocks, mixins, metaclasses, and beyond. Rather than bog you down with a lot of theory, The Book of Ruby takes a hands-on approach and focuses on making you productive from day one. As you follow along, you'll learn to:
- Leverage Ruby's succinct and flexible syntax to maximize your productivity
- Balance Ruby's functional, imperative, and object-oriented features
- Write self-modifying programs using dynamic programming techniques
- Create new fibers and threads to manage independent processes concurrently
- Catch and recover from execution errors with robust exception handling
- Develop powerful web applications with the Ruby on Rails framework
Each chapter includes a "Digging Deeper" section that shows you how Ruby works under the hood, so you'll never be caught off guard by its deceptively simple scoping, multithreading features, or precedence rules.
Whether you're new to programming or just new Ruby, The Book of Ruby is your guide to rapid, real-world software development with this unique and elegant language.
The Book of Ruby is an in-depth introduction to Ruby, one of the world's most popular programming languages and the backbone of the acclaimed Ruby on Rails web application framework. With an emphasis on writing clear and maintainable code, author Huw Collingbourne takes readers from the most basic constructs, like types, conditions, and loops, to more advanced techniques, like multithreading and metaprogramming. Rather than bog readers down with a lot of theory, The Book of Ruby takes a hands-on approach and focuses on the real-world issues that Ruby developers confront on a daily basis. Ready-to-run source code illustrates each topic, and all chapters and source code are self-contained, so experienced programmers can jump directly to the sections they need.
About the Author
Huw Collingbourne is the Director of Technology for SapphireSteel Software, developer of the Ruby In Steel IDE. With 30 years of programming experience, he has written programming columns for numerous magazines, presented features on computing for BBC Television, and currently edits the online technical journal Bitwise Magazine. He has previously released two free ebooks on Ruby—The Little Book of Ruby and The Book of Ruby.
Table of Contents
Acknowledgments; Introduction; What Is Ruby?; What Is Rails?; Matters of Ruby Style; How to Read This Book; Digging Deeper; Making Sense of the Text; Downloading Ruby; Getting the Source Code of the Sample Programs; Running Ruby Programs; The Ruby Library Documentation; Chapter 1: Strings, Numbers, Classes, and Objects; 1.1 Getting and Putting Input; 1.2 Strings and Embedded Evaluation; 1.3 Numbers; 1.4 Comments; 1.5 Testing a Condition: if..then; 1.6 Local and Global Variables; 1.7 Classes and Objects; Chapter 2: Class Hierarchies, Attributes, and Class Variables; 2.1 Superclasses and Subclasses; 2.2 Passing Arguments to the Superclass; 2.3 Accessor Methods; 2.4 Attribute Readers and Writers; 2.5 Calling Methods of a Superclass; 2.6 Class Variables; Chapter 3: Strings and Ranges; 3.1 User-Defined String Delimiters; 3.2 Backquotes; 3.3 String Handling; 3.4 Ranges; Chapter 4: Arrays and Hashes; 4.1 Arrays; 4.2 Hashes; Chapter 5: Loops and Iterators; 5.1 for Loops; 5.2 Blocks and Block Parameters; 5.3 Iterating upto and downto; 5.4 Multiple Iterator Arguments; 5.5 while Loops; 5.6 until Loops; 5.7 loop; Chapter 6: Conditional Statements; 6.1 if..then..else; 6.2 and, or, and not; 6.3 Negation; 6.4 if..elsif; 6.5 unless; 6.6 if and unless Modifiers; 6.7 Case Statements; Chapter 7: Methods; 7.1 Class Methods; 7.2 What Are Class Methods For?; 7.3 Class Variables; 7.4 Ruby Constructors: new or initialize?; 7.5 Singleton Methods; 7.6 Singleton Classes; 7.7 Overriding Methods; 7.8 Public, Protected, and Private Methods; Chapter 8: Passing Arguments and Returning Values; 8.1 Summarizing Instance, Class, and Singleton Methods; 8.2 Returning Values; 8.3 Returning Multiple Values; 8.4 Default and Multiple Arguments; 8.5 Assignment and Parameter Passing; 8.6 Integers Are Special; 8.7 The One-Way-In, One-Way-Out Principle; 8.8 Modifying Receivers and Yielding New Objects; 8.9 Potential Side Effects of Reliance on Argument Values; 8.10 Parallel Assignment; Chapter 9: Exception Handling; 9.1 rescue: Execute Code When Error Occurs; 9.2 ensure: Execute Code Whether or Not an Error Occurs; 9.3 else: Execute Code When No Error Occurs; 9.4 Error Numbers; 9.5 retry: Attempt to Execute Code Again After an Error; 9.6 raise: Reactivate a Handled Error; Chapter 10: Blocks, Procs, and Lambdas; 10.1 What Is a Block?; 10.2 Line Breaks Are Significant; 10.3 Nameless Functions; 10.4 Look Familiar?; 10.5 Blocks and Arrays; 10.6 Procs and Lambdas; 10.7 Block or Hash?; 10.8 Creating Objects from Blocks; 10.9 What Is a Closure?; 10.10 yield; 10.11 Blocks Within Blocks; 10.12 Passing Named Proc Arguments; 10.13 Precedence Rules; 10.14 Blocks as Iterators; Chapter 11: Symbols; 11.1 Symbols and Strings; 11.2 Symbols and Variables; 11.3 Why Use Symbols?; Chapter 12: Modules and Mixins; 12.1 A Module Is Like a Class . . .; 12.2 Module Methods; 12.3 Modules as Namespaces; 12.4 Included Modules, or "Mixins"; 12.5 Name Conflicts; 12.6 Alias Methods; 12.7 Mix In with Care!; 12.8 Including Modules from Files; Chapter 13: Files and IO; 13.1 Opening and Closing Files; 13.2 Characters and Compatibility; 13.3 Files and Directories; 13.4 Copying Files; 13.5 Directory Inquiries; 13.6 A Discursion into Recursion; 13.7 Sorting by Size; Chapter 14: YAML; 14.1 Converting to YAML; 14.2 Nested Sequences; 14.3 Saving YAML Data; 14.4 Omitting Variables on Saving; 14.5 Multiple Documents, One File; 14.6 A YAML Database; 14.7 Adventures in YAML; Chapter 15: Marshal; 15.1 Saving and Loading Data; 15.2 Omitting Variables on Saving; 15.3 Saving Singletons; Chapter 16: Regular Expressions; 16.1 Making Matches; 16.2 Match Groups; 16.3 MatchData; 16.4 Prematch and Postmatch; 16.5 Greedy Matching; 16.6 String Methods; 16.7 File Operations; Chapter 17: Threads; 17.1 Creating Threads; 17.2 Running Threads; 17.3 Going Native; 17.4 The Main Thread; 17.5 Thread Status; 17.6 Ensuring That a Thread Executes; 17.7 Thread Priorities; 17.8 The Main Thread Priority; 17.9 Mutexes; 17.10 Fibers; Chapter 18: Debugging and Testing; 18.1 IRB: Interactive Ruby; 18.2 Debugging; 18.3 Unit Testing; Chapter 19: Ruby on Rails; 19.1 Installing Rails; 19.2 Model-View-Controller; 19.3 A First Ruby on Rails Application; 19.4 Create a Rails Application; 19.5 Create a Controller; 19.6 Anatomy of a Simple Rails Application; 19.7 The Generate Controller Script Summarized; 19.8 Create a View; 19.9 Rails Tags; 19.10 Let's Make a Blog!; Chapter 20: Dynamic Programming; 20.1 Self-Modifying Programs; 20.2 eval; 20.3 Special Types of eval; 20.4 Adding Variables and Methods; 20.5 Creating Classes at Runtime; 20.6 Bindings; 20.7 send; 20.8 Removing Methods; 20.9 Handling Missing Methods; 20.10 Writing Programs at Runtime; 20.11 Exploring Further; Documenting Ruby with RDoc; Installing MySQL for Ruby on Rails; Downloading MySQL; Installing MySQL; Configuring MySQL; Can't Find the Database?; Further Reading; Books; Ebooks; Websites; Ruby and Rails Development Software; IDEs and Editors; Web Servers; Databases; Ruby Implementations; Colophon; Updates;