The Ruby Programming Language: Everything You Need to Know

Author: David Flanagan, Yukihiro Matsumoto
All Stack Overflow 22


by anonymous   2017-08-20

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:

  • Eloquent Ruby - teaches you the Ruby way in many chapters covering a wide spectrum of the Ruby language. Great read for polishing and enforcing your Ruby knowledge, and also great to re-read just to reinforce everything!
  • The Ruby Programming Language - co-authored by the author of Ruby himself, Yukihiro Matsumoto...need I say more? This is quite in-depth so not great for beginning to learn the language but great for helping you to master it.
  • The Well Grounded Rubyist - currently going through this book. It is well written and covers a lot of ground, good for getting the hang of Ruby, but probably assumes you're not a programming newbie.

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.

by Nolan Evans   2017-08-20

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 by matz and flanagan, the book is very concise well written paragraphs and they provide great examples (in 1.8.* and 1.9)

Enjoy! :D

by anonymous   2017-08-20

There is a method to this madness...

class Example
  @foo # class instance variable
  @@bar # class variable

  def fun1
    @baz # instance variable

Instance variables

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

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.

Class instance variable vs instance variable

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

by raghus   2017-08-19
If this is the book that's being referred to: then Flanagan's co-author was... Matz.
by jjburka   2017-08-19
I second the Rails Way book , its a great book thats easy to follow and organized. For learning Ruby I found to be great
by billturner   2017-08-19
Rails is such a fast moving target that keeping totally updated books on the shelves is probably just as frustrating for the book publishers as for those wanting up-to-date books.

That said, the Pragmatic Programmer's book Agile Development with Rails is a pretty good intro:

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 ( is a pretty good intro. David Black's The Well-Grounded Rubyist ( is recent, and I'm sure a great book, as his previous (Ruby for Rails) was excellent.