From: 7stud -- Newsgroups: comp.lang.ruby Subject: Re: basic ENCAPSULATION help Date: Wed, 30 Mar 2011 21:20:24 -0500 Organization: Service de news de lacave.net Lines: 37 Message-ID: References: <7ae35890c4342a71e3467ade701d3556@ruby-forum.com> NNTP-Posting-Host: bristol.highgroove.com Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Trace: talisker.lacave.net 1301538052 64668 65.111.164.187 (31 Mar 2011 02:20:52 GMT) X-Complaints-To: abuse@lacave.net NNTP-Posting-Date: Thu, 31 Mar 2011 02:20:52 +0000 (UTC) In-Reply-To: <7ae35890c4342a71e3467ade701d3556@ruby-forum.com> X-Received-From: This message has been automatically forwarded from the ruby-talk mailing list by a gateway at comp.lang.ruby. If it is SPAM, it did not originate at comp.lang.ruby. Please report the original sender, and not us. Thanks! For more details about this gateway, please visit: http://blog.grayproductions.net/categories/the_gateway X-Mail-Count: 380658 X-Ml-Name: ruby-talk X-Rubymirror: Yes X-Ruby-Talk: Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!news.stben.net!talisker.lacave.net!lacave.net!not-for-mail Xref: x330-a1.tempe.blueboxinc.net comp.lang.ruby:2015 One of the key aspects of a private method is: a private method cannot be called with an explicit "receiver". What does that mean? The receiver is the object calling the method. In the following example: class Dog def bark puts "woof" end end spot = Dog.new spot.bark --output:-- woof ..spot is the "receiver" and spot calls the method bark(). However, according to the rules of ruby, you cannot specify a receiver when you call a private method. Well, than how does ruby know which object is calling the method? Now you enter the tricky realm of what's known as 'self'. When a method is not called with a receiver, ruby implicitly uses whatever object is self at the instant the method is called. RULE #1: When ruby executes code inside a method, then inside the method self is equal to the object that called the method. So, for instance, in the example above, when spot calls bark(), inside bark(), self is equal to spot. What that implies is that you will usually call private methods from inside public methods. -- Posted via http://www.ruby-forum.com/.