Saved by Harold T. Harper
The Well-Grounded Rubyist
Harold T. Harper added
But 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.
Chris Pine • Learn to Program
Second, you define initialize in your class, but you never define new. (It’s already built into all classes.) Conversely, you call new to create an object, but you never call initialize. The method new takes care of that for you.
Chris Pine • Learn to Program
The first thing you noticed was probably the :: notation. Explaining the scope operator (which is what that is) is beyond the…uh…scope of this book. No pun intended. I swear. Suffice it to say, you can use Math::PI like any other variable, except that you can’t assign a new value to it. (And why would you want to?) This is because Math::PI is actua
... See moreChris Pine • Learn to Program
So, what’s the point? Why not use methods? As it turns out, there are some things you can’t do with methods. In particular, you can’t pass methods into other methods (but you can pass procs into methods), and methods can’t return other methods (but they can return procs). This is simply because procs are objects; methods aren’t.