Working With Unix Processes
Harold T. Harper added
Harold T. Harper added
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 moreChris Pine • Learn to Program
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
So why is puts printing 8 for var2 instead of "luck"? Good question. The issue here is that var2 was never really pointing to var1. Variables can’t point to other variables, so var2 was actually pointing to 8 the whole time.