The problem with class variables in Ruby is that when you inherit from a class then the new class does not get a new copy of its own class variable but uses the same one that it inherited from its superclass.
For example:
class Car
@@default_max_speed = 100
def self.default_max_speed
@@default_max_speed
end
end
class SuperCar < Car
@@default_max_speed = 200 # and all cars in the world become turbo-charged
end
SuperCar.default_max_speed # returns 200, makes sense!
Car.default_max_speed # returns 200, oops!
The recommended practice is to use class instance variables (remember that classes are simply objects of class Class in Ruby). I highly recommend reading Chapter 14 of Eloquent Ruby by Russ Olsen, which covers this topic in detail.
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.
Ruby Best Practices by Gregory Brown - By this point you should be ready for the advanced level of this book.
Rails for Zombies - Fun tutorial you can complete in an afternoon.
Rails Tutorial by Michael Hartl - Fantastic (and free) tutorial and I have heard his accompanying screencasts are amazing.
Agile Web Development with Rails by Sam Ruby - By the time you are finished this you are now a completely capable Rails person!
Aside from books the most important thing is to get feedback on what you are doing. To do this I recommend spending time in irc.freenode.net #ruby and #rubyonrails. It is also extremely helpful to post things you are working on or having trouble with here on stackoverflow as the comments, explanations and different way of thinking about things that people provide are invaluable.
You should also definitely check out the Ruby Rogues podcast, they provide invaluable information and the commentators are all extremely respected people in the Ruby community. And for your viewing and reading pleasure (in that order,) head over to Ryan Bates's Railscasts and then Eifion Bedford's Asciicasts.
Finally, I recommend looking into different gems on github, reading the code and then contributing to them. You don't have to get overly ambitious and do massive recodes, especially at first. Just start with small things like editing and making the README files a little easier to read.
I don't use an IDE but at Railsconf I saw a demo of Rubymine from Jetbrains and it seemed pretty amazing.
The problem with class variables in Ruby is that when you inherit from a class then the new class does not get a new copy of its own class variable but uses the same one that it inherited from its superclass.
For example:
The recommended practice is to use class instance variables (remember that classes are simply objects of class Class in Ruby). I highly recommend reading Chapter 14 of Eloquent Ruby by Russ Olsen, which covers this topic in detail.
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.
My recommendation. In order to read:
Fantastic decision! It is extremely useful to get a grounding in Ruby before going to Rails so here is my take on the best path to Rails:
Aside from books the most important thing is to get feedback on what you are doing. To do this I recommend spending time in irc.freenode.net #ruby and #rubyonrails. It is also extremely helpful to post things you are working on or having trouble with here on stackoverflow as the comments, explanations and different way of thinking about things that people provide are invaluable.
You should also definitely check out the Ruby Rogues podcast, they provide invaluable information and the commentators are all extremely respected people in the Ruby community. And for your viewing and reading pleasure (in that order,) head over to Ryan Bates's Railscasts and then Eifion Bedford's Asciicasts.
Finally, I recommend looking into different gems on github, reading the code and then contributing to them. You don't have to get overly ambitious and do massive recodes, especially at first. Just start with small things like editing and making the README files a little easier to read.
I don't use an IDE but at Railsconf I saw a demo of Rubymine from Jetbrains and it seemed pretty amazing.