Ruby Cookbook
By Lucas Carlson, Leonard Richardson
July 2006
Pages: 906
Series: Cookbooks
ISBN 10: 0-596-52369-6 |
ISBN 13: 9780596523695




(Average of 6 Customer Reviews)


Book description
From data structures and algorithms, to integration with cutting-edge technologies, the Ruby Cookbook has something for every programmer. When you need to solve a problem, don't reinvent the wheel: look it up in the Cookbook.
Full Description
Do you want to push Ruby to its limits? The Ruby Cookbook
is the most comprehensive problem-solving guide to today's hottest
programming
language. It gives you hundreds of solutions to real-world problems,
with clear explanations and thousands of lines of code you can use in
your own projects.
From data structures and algorithms, to integration with
cutting-edge technologies, the Ruby Cookbook has
something for every programmer. Beginners and advanced Rubyists
alike will learn how to program with:
- Strings and numbers
- Arrays and hashes
- Classes, modules, and namespaces
- Reflection and metaprogramming
- XML and HTML processing
- Ruby on Rails (including Ajax integration)
- Databases
- Graphics
- Internet services like email, SSH, and BitTorrent
- Web services
- Multitasking
- Graphical and terminal interfaces
If you need to write a web application, this book shows you
how to get started with Rails. If you're a system administrator who
needs to
rename thousands of files, you'll see how to use Ruby for this and
other everyday tasks. You'll learn how to read and write Excel
spreadsheets, classify text with Bayesian filters, and create PDF
files. We've even included a few silly tricks that were too cool to
leave out, like how to blink the lights on your keyboard.
The Ruby Cookbook is the most useful book yet
written about Ruby. When you need to solve a problem, don't reinvent
the wheel: look it up in
the Cookbook.
Browse within this book
Cover
| Table of Contents
Featured customer reviews

A really good book,
January 28 2007
Submitted by
Jeremiah
[
Respond |
View]
This book is a must-have for any programmer just discovering Ruby. The examples are straight forward and relevant. Combine this with a good Rails book and you have just what you need to get started on a serious project.
Ruby Cookbook Review,
December 21 2006
Submitted by
Vince W.
[
Respond |
View]
This review was originally published for RubyDC on Urbanpuddle.com:
Life is short, proclaims the authors of O'Reilly's Ruby Cookbook. You have real problems and this book is here to solve them, they go on. Weighing in at around 850 pages, there certainly is a chance that what ever problem you have could be addressed in this book. But is it all cartoon foxes or a tale with descriptions and plot twists worthy of reading in your bathrobe over a cup of chamomile? Thankfully no. In this book, O'Reilly delivers a densely packed tome filled with information, most of it unrelated, intended to solving real problems.
If you've never used a recipe book before, the premise is simple. They teach you how to put together code to create a particular effect or output. Reading tons of code on paper can be awfully boring but thankfully Ruby lends itself well to these types of books largely because it's a human readable language and packs a lot of functionality in very little space. For instance, you can expect:
<% 3 times.do %> yeah
Will output yeah yeah yeah as you would expect when reading
three times, do 'yeah'. In the Ruby Cookbook, authors Lucas Carlson and Leonard Richardson have divided the problems into these logical groups:
1. Strings
2. Numbers
3. Date & Time
4. Arrays
5. Hashes
6. Files & Directories
7. Code Blocks & Iterations
8. Objects & Classes
9. Modules & Namespaces
10. Reflections & Metaprogramming
11. XML & HTML
12. Graphics and Other File Formats
13. Databases & Persistence
14. Internet Services
15. Web Development: Ruby on Rails
16. Web Services and Distributed Programming
17. Testing, Debugging, Optimizing, and Documenting
18. Packaging and Distributing Software
19. Automating Tasks with Rake
20. Multitasking and Multithreading
21. User Interface
22. Extending Ruby with Other Languages
23. System Administration
As you can see there is a lot of information in this book. <tangent>As I was flipping through it I began to wonder how I could possibly make room in my brain for all this knowledge. If I absorbed it all I'd probably have to discard some pretty fundamental things like remembering to zip up my fly. Trust me, nobody wants that. My guess is that Mssrs. Carlson & Richardson are in similar predicaments and my thanks to go them and their Significant Others for potentially sacrificing valuable basic skills in order to bring you all this wonderful code. </tangent>
Each recipe in the book is divided into three sections: Problem, Solution, and Discussion. As you can infer, the problem gives a concise description of the issue that the Solution will then resolve. The Solution portion is where most of the code is and, like all O'Reilly books, they do a good job of separating the text from code so there's never any confusion. The Discussion is often the longest part of the recipe and contains not only details on the solution but the occasional alternative approach as well.
I can't say that each recipes contained in this book is staggeringly useful. For instance, I personally do not foresee ever needing 2.14: Doing Math with Roman Numbers. But I guess some would-be gladiators out there might find that helpful. But the recipes that I did find interesting were very valuable and made the price of the book well worthwhile. I particularly enjoyed the recipes on Classifying Text with a Bayesian Analyzer, Documenting Your Website, and Checking a Credit Card Checksum.
Other recipes, while not urgently required, can add a polish and professionalism to your code to set you apart from your peers. For instance there is a very simple recipe for wrapping text which you can use as an alternative to truncating:
def wrap(s, width=78)
s.gsub(/(.{1,#{width}})(\s+|Z)/, "\\1\n")
end
Using it like: puts wrap("This text is not too short to be wrapped.", 20)
I did find some solutions a little lacking. The Sending Mails with Rails recipe is different enough from the similar recipe in Chad Fowler's Rails Recipes book to make it useful. Neither solution independently helped me craft a newsletter function for my website but both combined gave me the knowledge I needed to write my code the way I needed it. Likewise, Generating PDF Files recommended using PDF-Writer which I found slow for the amount of fields (> 200) and records (> 500) that I need for my application. Based on a recommendation from a fellow RubyDC member, I will be checking out Ruport and RTex to see if it helps. Honestly, it could be that all solutions give me the same headaches.
Overall I was really impressed with the book. As with any recipes book, the utility is directly proportional to your need. Ruby Cookbook is no different there. It makes sense that, since each program is unique, some proposed solutions won't fit perfectly. Yet they will still otherwise give you a great launching point towards finding your own answer! Most importantly, as the types of applications you need to code change and as their complexity grow, you will find methods to avoid many of the usual speedbumps along the way within these pages.
Ruby Cookbook Review,
November 30 2006
Submitted by
Brian Anderson
[
Respond |
View]
I've looked at a couple programming “cookbooks” over the few years I've been programming, and none have ever really captured my attention. Most of them I found were lacking in useful recipes for novice programmers, or the recipes used an outdated code style or covered specific areas of a programming language. And with others, I just found it difficult to find useful tips or tricks.
The Ruby Cookbook however, provides fresh, easy to read recipes that are full of neat tips and awesome tricks. And it's all provided in an easy to read, and more importantly easy to find, format. Programmers from novice to highly experienced will find this book useful.
The book is laid out using general data types as chapters at first, then moves into more abstract topics such as code blocks and modules; databases and persistence; web services and task automation with Rake.
Start with the table of contents to learn about a specific area, or thumb your way through the index to find specific topics or that fast piece of code you need to complete your project. No matter how you use it, the Ruby Cookbook is a must have book for any Ruby or Ruby on Rails programmer.
Read all reviews
This Book is a Gem!,
October 03 2006
Submitted by
Dave Walz-Burkett
[
Respond |
View]
Sometimes, the difference between getting a project off the ground and watching it linger on the launchpad is finding an example of how to do something in code.
Perhaps you're working on a project and you'd like to send an email using Ruby. Maybe you'd like to know how to read and write zip files or create thumbnail images from full size graphics files. Sometimes cruising through the API documentation just doesn't quite give you enough info.
The Ruby Cookbook fills the void for a portable version of a Ruby code snippet search engine. For each example, there is a
Problem description, a
Solution section containing one or more chunks of Ruby code and a
Discussion section for follow-up. Most examples also have a
See Also section for cross reference.
A huge amount of material is covered. Topics range from simple stuff like strings, numbers, hashes, arrays and objects to more challenging subjects like code blocks, reflection, metaprogramming and multithreading. It has chapters on Internet services, Web services and distributed programming, and Web development with Ruby on Rails.
I'm only just skimming the surface here, this is a
big book with 873 pages. It is quite simply
packed with goodies. There is something in this book for Ruby programmers at every level. The book is well written and easy to read. You can download a zip file containing all of the code samples from the O'Reilly website.
If you want to learn Ruby and Ruby on Rails, there are three books that will help you more than anything else: Programming Ruby by Dave Thomas, Agile Web Development with Rails by Dave Thomas and David Heinemeier Hansson and the Ruby Cookbook by Lucas Carlson and Leonard Richardson.
A 'must -have' book,
August 05 2006
Submitted by
Satish Talim
[
Respond |
View]
This book is a '
must-have' for all the Ruby enthusiasts. I hope they put up a .zip file of all the programs here.
Excellent Book,
July 25 2006
Submitted by
Vinodh Kumar
[
Respond |
View]
Super book from Beginers to Advanced.
Media reviews
"I've lost count of the times I've googled for ages for some ruby trick and found it in the Cookbook in about 10 seconds. It's brilliant, and the discussion sections always highlight something useful. "
-- Ashley Moran, Business Analyst, Codeweavers.net,
Comp.lang.ruby
"If you would like to become a serious Ruby hacker, dont hesitate to buy this book. In my opinion it is absolutely worth every cent - and even more. My only problem is that there are no more recipes - however this is not a critique but rather a compliment: you simply can not get enough - not even from nearly 900 pages. One could argue that some things are missing or he would rather see this instead of that (I believe the authors themselves have had some tough time deciding these matters) - but I guess everyone agrees that the material which made it to the book is absolutely top-notch. 5 out of 5 stars - a great addition to anyones Ruby bookshelf.
"
-- Peter Szinek, MSc,
RubyRailways
"...906 pages of shiny, nearly perfect Ruby code with detailed explanations of everything, this book is a fantastic way to learn Ruby."
-- Joel Spolsky,
Joel on Software
Read all reviews