Sunday, March 13, 2011

Ruby by Example: Concepts and Code



Ruby by Example: Concepts and Code
| 2007-06-08 00:00:00 | | 0 | Ruby


There may be no better way to learn how to program than by dissecting real, representative examples written in your language of choice. Ruby by Example analyzes a series of Ruby scripts, examining how the code works, explaining the concepts it illustrates, and showing how to modify it to suit your needs. Baird's examples demonstrate key features of the language (such as inheritance, encapsulation, higher-order functions, and recursion), while simultaneously solving difficult problems (such as validating XML, creating a bilingual program, and creating command-line interfaces). Each chapter builds upon the previous, and each key concept is highlighted in the margin to make it easier for you to navigate the book.

You'll learn how to: Use the interactive Ruby shell (irb) to learn key features of the language Extend Ruby using RubyGems, the Ruby package manager Create numerical utilities, as well as utilities that process and analyze HTML/XML Implement purely functional and metaprogramming techniques to save time and effort Optimize, profile, and test your code to make sure that it not only does its job, but does it well Create web applications using Rails

Ruby is the fastest growing programming language today, and for good reason: Its elegant syntax and readable code make for prolific and happy programmers. But it can be difficult to understand and implement without a little help. Ruby by Example shows you how to take advantage of Ruby as you explore Ruby's fundamental concepts in action.

User review
I didn't like it.
I ended up making it like 50 pages through the book and just giving up and buying the O'Reilly Learning Ruby. I've been a professional software developer for more than 20 years and I thought I wouldn't have any problem learning Ruby this way. The problem is that he just did some things in a weird way and really didn't explain everything in the code like I expected. I spent a lot of time going 'uh', 'huh?' and 'I don't get it.' I hate not finishing a book.


In many examples, I just couldn't understand how he got to where he got or why he did it the way he did. I guess it's a cool book to learn weird ways to accomplish things in Ruby, but did nothing for me.

User review
Some minor flaws, but a great book overall
Ruby by Example is a great introduction to the Ruby Language. It is not without some flaws, though. The book has good pacing, but seems at times to jump around or not explain everything as clearly as I would have liked. In chapter 3, I would have liked more description of how the my_join method was actually working on the variable, and why the author used self.dup to create a duplicate set of data to work on. This got lost in a discussion about protected methods, and popping elements out of a list. That said, this book does have well thought-out examples, and does provide a great springboard for learning Ruby. Highly recommended.



User review
Ruby progrmming language.
The book came very fast in the mail. It was new in quality. I am able to teach myself Ruby from the book.

User review
Simply Excellent,,.
If you want to learn Ruby quickly and you can only afford to buy one book to do it with, this is the one I would buy! It has interesting little projects with well documented code which introduces you gradually to more advanced topics in the language. It is not a cookbook, but rather, a very well picked selection of programmes where new concepts are thoroughly explained and older concepts are reinforced. There are `hacks` to just about every script and I was able to learn more from this than I did from grinding through the Pick Axe. Amazingly, now when I pick up the Pick Axe it seems accessible!


Well worth the investment!

User review
Tries something a bit different, is mostly successful
Ruby By Example seeks to teach Ruby by introducing a series of small scripts, explaining how they work, often by showing some examples in irb, Ruby's interactive shell, and reinforcing the explanations with some suggested modifications to the script to highlight the principles just expounded. The closest examples in other languages I'm aware of are Dive Into Python and (to a lesser extent) Wicked Cool Perl Scripts.


This is a very nice idea, and there are some examples that are a cut above the usual fare: chapter 9 includes a Bible Code generator, and an implementation of the 'methinks it is like a weasel' sentence natural selection program from Richard Dawkins' The Blind Watchmaker. There's also mention of memoization, profiling and benchmarking, the Schwartzian transform for sorting, and even Symbol#to_proc. There's also quite a gentle introduction to Rails, which is probably sufficient for someone new to Ruby and Rails to move onto Ruby for Rails.


However, the execution isn't always perfect. Probably the biggest downside to this pedagogical approach is that there's not really one obvious place to describe how a particular feature works in depth, or the focus moves away from its practical use in a script. As a result, many of the explanations are compressed. Chapter 1 provides a 'crash' description of object orientation in 9 lines. Chapter 3 first mentions hashes, but compares them to functions, and not to arrays. Tail recursion is defined in a 4 line footnote in chapter 7. If you already understand these concepts, you'll be fine, but they won't teach you anything. If you don't, they aren't very helpful. At a couple of points the book also insists that everything in Ruby is an object, but code blocks (among other things) aren't until they're wrapped in Procs. For the more functional-esque techniques advocated in the book, this is a subtle point which could trip up a beginner.


Also, some of the examples are weak. Chapter 4 rushes through regular expressions, using them to compress whitespace, but why not also mention String#squeeze? Chapter 5 uses regexes to deal with XML and it gets the job done, but advice on using a real XML parser might have been more useful in the long term. Chapter 6 contains a truly contrived Buffy the Vampire Slayer-related example.


This isn't a bad introduction to Ruby, and it's a very admirable attempt to do something different, but I wanted to like it more than I did. If you already know some object oriented programming, this could make a good companion to a more tutorial-style book, like The Pickaxe.


Download this book!

Free Ebooks Download