The Book of Ruby: A Hands-On Guide for the Adventurous
By Huw Collingbourne
(No Starch Press, $39.95, paperback; $31.95, Kindle)
Ruby, first introduced in 1995, is “a cross-platform interpreted language that has many features in common with other ‘scripting’ languages such as Perl and Python,” says Huw Collingbourne, who is director of technology for SapphireSteel Software and has 30 years’ experience in computer programming.
“Many people are attracted to Ruby by its simple syntax and ease of use. They are wrong,” he cautions in his new book. “Ruby’s syntax may look simple at first sight, but the more you get to know the language, the more you will realize that it is, on the contrary, extremely complex. The plain fact of the matter is that Ruby has a number of pitfalls just waiting for unwary programmers to drop into.”
Collingbourne has written The Book of Ruby to help those new to the programming language successfully jump over the hazards. Ruby, he notes, can look a bit like Pascal at first glance. But: “It is thoroughly object-oriented and has a great deal in common with the granddaddy of ’pure’ object-oriented languages, Smalltalk.”
He cautions programmers to get a good handle on Ruby by itself before rushing ahead to use the popular web development framework known as Ruby on Rails.”Understanding Ruby is a necessary prerequisite for understanding Rails,” he warns.
“Indeed, if you were to leap right into Rails development without first mastering Ruby, you might find that you end up creating applications that you don’t even understand. (This is all too common among Ruby on Rails novices.)”
Collingbourne’s well-written 373-page book covers Ruby 1.8 and 1.9. He takes a “bite-sized chunks” approach, so that each chapter “introduces a theme that is subdivided into subtopics.” And: “Each programming topic is accompanied by one or more small, self-contained, ready-to-run Ruby program.”
The chapter line-up shows the book’s structure:
- 1: Strings, Numbers, Classes, and Objects
- 2: Class Hierarchies, Attributes, and Class Variables
- 3: Strings and Ranges
- 4: Arrays and Hashes
- 5: Loops and Iterators
- 6: Conditional Statements
- 7: Methods
- 8: Passing Arguments and Returning Values
- 9: Exception Handling
- 10: Blocks, Procs, and Lambdas
- 11: Symbols
- 12: Modules and Mixins
- 13: Files and IO
- 14: YAML
- 15: Marshal
- 16: Regular Expressions
- 17: Threads
- 18: Debugging and Testing
- 19: Ruby on Rails
- 20: Dynamic Programming
- Appendix A: Documenting Ruby with RDOC
- Appendix B: Installing MySQL for Ruby on Rails
- Appendix C: Further Reading
- Appendix D: Ruby and Rails Development Software
The author gives links for downloading the latest version of Ruby, plus the source code for all of the programs used in this book.
Collingbourne notes that The Book of Ruby “covers many of the classes and methods in the standard Ruby library – but by no means all of them! At some stage, therefore, you will need to refer to documentation on the full range of classes used by Ruby.” He provides links to the online documentation for both Ruby 1.8 and Ruby 1.9.
True to his word, he begins at the “hello world” level of Ruby:
puts 'hello world'
From there, he keeps surging forward in small, careful steps, offering good examples to illustrate each new topic. In each chapter except the Introduction, he also includes a subsection known as “Digging Deeper.”
“In many cases, you could skip the ‘Digging Deeper’ sections and still learn all the Ruby you will ever need,” he states. “On the other hand, it is in these sections that you will often get closest to the inner workings of Ruby, so if you skip them, you are going to miss out on some pretty interesting stuff.”
Collingbourne previously has released two free ebooks on Ruby: The Little Book of Ruby and The Book of Ruby.
He knows his Ruby – and he wants you to know this elegant and unique programming language, too.
– Si Dunn