About this Book – Ruby in Practice

About this Book

Welcome to Ruby in Practice! This book is geared toward software developers who know Ruby or who are starting with Ruby and want to put their skills to use solving real software-development problems. We’ll walk you through a series of common software scenarios, such as authenticating against LDAP or parsing XML, and show you how to approach and easily solve them using Ruby.

These solutions (and the chapters themselves) are discrete units that can be read in any order. If you’re not interested in the web-related chapters, feel free to skip them. If you really want to learn all about reporting, skipping past the other chapters shouldn’t affect your ability to understand that one. While we do suggest that you read them in order (because some chapters will make at least a little more sense after reading others), you don’t have to. And, fear not: if a concept is discussed elsewhere in the book, it is noted so that you can find it easily enough.

Who should read this book

Ruby is gaining steam both on and off the web. This book is geared toward developers who want to explore using Ruby in environments that aren’t necessarily “database-backed web applications.” Experience in Ruby is assumed (and is fairly essential to get the maximum value from most of the discussions), but you don’t need to be an expert to get started with this book. Even beginners will find their place, learning from examples that range from practical solutions to development challenges.

What this book doesn’t include

This book isn’t an introduction to the Ruby language. While it does discuss a number of language techniques, these discussions assume a working knowledge of Ruby. There is very little hand-holding when it comes to understanding the fundamentals of the code examples, so you would do well to either learn Ruby or at the least pick up a book to refer to when you come to something you don’t understand.

This book also does not contain much introductory information on Rails. It is discussed in a few chapters (specifically in chapter 4), it’s used as an example for various techniques, and it’s often referred to in relation to web applications with Ruby, but this book will not teach you Ruby on Rails. Of course, it’s not essential to know Rails to enjoy this book; you can read the whole book blissfully unaware of what alias_method_chain is. But if you are interested in learning it, we recommend you get one of the many books on the topic, since they cover it better than we could in the small space we devote to it.

How this book is organized

Ruby in Practice is composed of 13 chapters divided into 3 parts.

  • Part 1—Ruby techniques
  • Part 2—Integration and communication with Ruby
  • Part 3—Ruby data and document techniques: Working with some form of data is the fundamental task of any application.

Part 1 (chapters 1-3) discusses techniques that will be useful when you start applying what you learn in the rest of the book. Techniques include metaprogramming and DSLs, testing and BDD, scripting and automating tasks.

Chapters 4-8 (part 2 of Ruby in Practice) are arranged in a problem/solution/ discussion format, covering topics related to systems integration and communications. We discuss web services, messaging systems, e-mail and IM, and so on, and we show you how to put these technologies to use in your Ruby applications.

Part 3 (chapters 9-13) follows the same format, but focuses on data, presentation, and security. We discuss databases, parsing and generating XML, reporting, authentication, and so on. These chapters will equip you to work in a data-driven environment using Ruby as your primary tool.

The appendices cover topics related to the book, but they’re not specific to any particular chapter. Appendix A is a quick treatise on getting a good Ruby environment set up on your system. Appendix B covers JRuby: how to install it, how to use Java with Ruby, and how to deploy Rails applications as WAR files. Appendix C discusses deploying Ruby web applications.

Code conventions

All source code in the book is in a monospace font, which sets it off from the surrounding text. For most listings, the code is annotated to point out key concepts, and numbered bullets are sometimes used in the text to provide additional information about the code. Sometimes very long lines will include line-continuation markers.

In the text, names of Ruby methods, classes, modules, and constants are also in a monospace font. Names of programs, such as ruby and java, are monospace when referring to the program executable or command-line usage; otherwise, they appear in regular type. Book and article titles, and technical terms on first mention, appear in italics.

Code downloads

The complete source code for the examples in this book is available for download from the publisher’s web site at http://www.manning.com/RubyinPractice. This includes any code used in the book, with accompanying tests or spec files. A more frequently updated and forkable version of the code (meaning that you can clone your own version and make changes to be pushed back to our mainline version) is available at http://www.github.com/assaf/ruby-in-practice/.

Author online

The purchase of Ruby in Practice includes free access to a private forum run by Manning Publications where you can make comments about the book, ask technical questions, and receive help from the authors and other users. You can access and subscribe to the forum at http://www.manning.com/RubyinPractice. This page provides information on how to get on the forum once you’re registered, what kind of help is available, and the rules of conduct in the forum.

Manning’s commitment to our readers is to provide a venue where a meaningful dialogue between individual readers and between readers and the authors can take place. It isn’t a commitment to any specific amount of participation on the part of the authors, whose contributions to the book’s forum remain voluntary (and unpaid). We suggest you try asking the authors some challenging questions, lest their interest stray!

The Author Online forum and the archives of previous discussions will be accessible from the publisher’s website as long as the book is in print.

About the cover illustration

The illustration on the cover of Ruby in Practice is taken from a collection of costumes of the Ottoman Empire published on January 1, 1802, by William Miller of Old Bond Street, London. The title page is missing from the collection and we have been unable to track it down to date. Each illustration bears the names of two artists who worked on it, both of whom would no doubt be surprised to find their art gracing the front cover of a computer programming book...two hundred years later.

The collection was purchased by a Manning editor at an antiquarian flea market in the “Garage” on West 26th Street in Manhattan. The seller was an American based in Ankara, Turkey, and the transaction took place just as he was packing up his stand for the day. The Manning editor did not have on his person the substantial amount of cash that was required for the purchase and a credit card and check were both politely turned down. With the seller flying back to Ankara that evening the situation was getting hopeless. What was the solution? It turned out to be nothing more than an old-fashioned verbal agreement sealed with a handshake. The seller simply proposed that the money be transferred to him by wire and the editor walked out with the bank information on a piece of paper and the portfolio of images under his arm. Needless to say, we transferred the funds the next day, and we remain grateful and impressed by this unknown person’s trust in one of us. It recalls something that might have happened a long time ago.

The pictures from the Ottoman collection, like the other illustrations that appear on our covers, bring to life the richness and variety of dress customs of two centuries ago. They recall the sense of isolation and distance of that period—and of every other historic period except our own hyperkinetic present.

Dress codes have changed since then and the diversity by region, so rich at the time, has faded away. It is now often hard to tell the inhabitant of one continent from another. Perhaps, trying to view it optimistically, we have traded a cultural and visual diversity for a more varied personal life. Or a more varied and interesting intellectual and technical life.

We at Manning celebrate the inventiveness, the initiative, and, yes, the fun of the computer business with book covers based on the rich diversity of regional life of two centuries ago, brought back to life by the pictures from this collection.