The Ruby Programming Language: Everything You Need to Know
I took up Rails with the Agile Web Development with Rails 2nd Edition. I have their latest (4th) edition and recommend it, but there are lots of other resources out there now.
One in particular that I would very much recommend is the free Ruby on Rails Tutorial by Michael Hartl. It's up to date and teaches you how to use not only Ruby and Rails, but also other modern and important tools such as RVM for Ruby/gem management, Git for version control and RSpec for testing. It encourages a great test-driven workflow, so I'd recommend it even if you're not a beginner. I actually used this tutorial a few months back to refresh my memory and get into the new Rails 3 after having been out of it for over a year.
After you're comfortable with the Rails framework, then you should learn the Ruby language it is built upon. This is the stage I am at. Some of the books I'd recommend for learning Ruby are:
Obviously this is based on my experience and recommendations I have received from friends and colleagues, so I'm not saying this is the path for everyone interested in Ruby/Rails, but so far it's working for me. I'll be interested in seeing what resources others recommend here.
I would use pure ruby (Matz Ruby Interpreter (MRI)) to start off. My understanding is that iron ruby is not quite ready yet.
If you are looking for a good book my current favorite (over pickaxe) is http://www.amazon.com/gp/product/0596516177 by matz and flanagan, the book is very concise well written paragraphs and they provide great examples (in 1.8.* and 1.9)
There is a method to this madness...
@foo # class instance variable
@@bar # class variable
@baz # instance variable
Instance variables (@foo and @baz in the example) always begin with @, and they always belong to whatever object self refers to: either an object of the class, or the Class object representing a class. An instance variable reference in a class definition or class method is completely different from an instance variable reference in an instance method.
Because instance variables are not defined by a class, they are unrelated to the inheritance mechanism —they are simply created when a value is assigned to them. Class instance variables, being simply instance variables of the Class object that represents a class, are thus not inherited.
Class variables are visible to, and shared by, the class methods and the instance methods of a class, and also by the class definition itself. Class variables can be used in instance methods, class methods, and in the class definition itself, outside of any method. Class variables are always evaluated in reference to the class object created by the enclosing class definition statement.
A disadvantage of class instance variables is that they cannot be used within instance methods as class variables can. Another disadvantage is the potential for confusing them with ordinary instance variables. An advantage of class instance variables over class variables has to do with the confusing behavior of class variables when subclassing an existing class: if a class uses class variables, then any subclass can alter the behavior of the class and all its descendants by changing the value of the shared class variable. This is a strong argument for the use of class instance variables instead of class variables.
Much of this is from the excellent "The Ruby Programming Language"
alt text http://ecx.images-amazon.com/images/I/517LDwIEYwL._SL75_.jpg
That said, the Pragmatic Programmer's book Agile Development with Rails is a pretty good intro: http://pragprog.com/titles/rails3/agile-web-development-with...
But, with Rails 3 (with many changes) coming in the next few months, books are going to become outdated yet again.
As for Ruby in general, the fairly recent The Ruby Programming Language (http://www.amazon.com/Ruby-Programming-Language-David-Flanag...) is a pretty good intro. David Black's The Well-Grounded Rubyist (http://www.amazon.com/Well-Grounded-Rubyist-David-Black/dp/1...) is recent, and I'm sure a great book, as his previous (Ruby for Rails) was excellent.