
Saved by Harold T. Harper
The Well-Grounded Rubyist
Saved by Harold T. Harper
That leaves the puts and gets methods to explain. Where are their objects? In English, you can sometimes leave out the noun; for example, if a villain yells “Die!” the implicit noun is whomever they’re yelling at. In Ruby, if you say puts "to be or not to be", the implicit object is whatever object you happen to be in. But hang on, you do
... See moreBut don’t methods always have to be associated with objects? Well, yes, they do, and in this case (as with puts and gets), the method is associated with the object representing the whole program.
The reason for having these two methods is that you need one of them to be a class method and the other to be an instance method. If you think about it, new has to be a class method, because when you want to create an object, the object you want doesn’t exist yet. You can’t say die.new, for example, because die doesn’t exist yet. And initialize has
... See more