Wednesday, August 29, 2012

Ruby on Rails and TDD/BDD Books

After several-month web development in Ruby on Rails, I feel it may be a good time for me to conclude a lit bit about those Ruby on Rails books & materials I've read (far away from complete and welcome recommendations). No matter how many books we read, reading is just a start and approach of learning. More important is getting our hands dirty with code and development!!!


Ruby on Rails Tutorial-Learn Web Development with Rails
Best Ruby on Rails book for introduction! It provides great big pictures, good development practice (TDD/BDD) as well as necessary details for us to understand why besides how. (I still refer to this book time to time, after reading for 3 times)


Agile Web Development with Rails (4th edition)
After reading through "Ruby on Rails Tutorial" listed above, I got to this book which is also our cloud computing textbook. It's a good complement to the tutorials and opens a door to larger area of Rails. The only thing I'm not used to is they use Test::Unit in this book instead of RSpec+Capybara+Cucumber.


The RSpec Book: Behaviour-Driven Development with RSpec, Cucumber, and Friends
I'm a big fan of this book!!! Strongly recommend it to anyone who wanna be a developer in TDD/BDD. I can still remember the excitement when I read this book. It brought me to a brand new development world, totally different from the one I was in. Some parts look more like a reference book, so I decided to leave the remaining reading for the time I need it (familiar with my idea?  Just borrowed it from some corners of this book and Extreme Programming. I first read this design principle in Design Patterns In Ruby, which book I'll also talk about in other post). I've been conforming to the practice in all Rails & Ruby developments since reading this book, benefiting a lot. 


Rails 3 Way (2nd Edition)
A great reference book I always resort to besides online manual. It's also helpful to read through the book chapter by chapter (I've studied a lot by reading just a few chapters. Of course, there are still hundreds of pages left for my future reading...)


Ruby books (I'll publish another post about Ruby books, so here only give two references):
1. The Ruby Programming Language 
2. Programming Ruby 1.9 (3rd edition): The Pragmatic Programmers' Guide (also called the Pickaxe Book)
I don't need to say anything about these two excellent books. I always keep them on my desk for reference or just for review reading. Only regret I started my Ruby study using the 1st one. My life should have been much happier if I went along with the Pickaxe Book...


Online materials:
Ruby on Rails Documentation
The first place I resort to when getting confusion in reading and coding. But sometimes the content lack details, so I'll turn to Rails 3 Way or Ruby on Rails - APIdock where we also turn to when stuck with Ruby and RSpec.


Ruby on Rails Guides
After I studies "Ruby on Rails Tutorial" and "Agile Web Development with Rails", this is the place I read to expand my Rails knowledge. It's not bad to read it section by section, when you feel confident with developing web app using Rails. When you read "RoR Guides", you probably won't feel so excited as reading the first two or three books of Rails. It's more like a review... (You may not think so if "RoR Guides" is the first material you read after finishing "Ruby on Rails Tutorial")

 

Friday, August 24, 2012

A quick review of singleton class(eigenclass) and class methods

First think about an object(o1)'s singleton methods.
For a method used just by this object(o1), you can't define a method in its class, since this will make this method available to all instances of the object's class. (An Class object in Ruby actually only have instance methods like:

class C1
def met1
# ...
end
end

Class method is more like an abstraction concept)

So we add an anonymous object (anon) between the object and its class, since this anon object only exists as a new class of the object and subclass of the object's original class, all its instance methods can be only called by the object, so this anon object is the singleton class(eigenclass) of the object o1, and its instance methods are singleton methods for the object o1.

Second,
If the object o1 represents a class (for example, o1's class is class Class), it can have its own methods, but these are instance methods that will be used by all its instances, not by herself.

Based on the above explanations, we'll have a singleton class for this o1 if we considering this class object as an object (a lit confusing, but don't forget everything in Ruby is an object). The instance methods in this singleton class can only be called by the class object o1 and they're actually the class methods we saw in:

class C1
def self.met2
#...
end
end 

To help understand, I borrow the pics from the classical the Pickaxe Book: Programming Ruby 1.9. The big arrow indicates the addition of single method to the class object Dave (equivalent to class object o1 above)