X-FeedAbuse: http://nntpfeed.proxad.net/abuse.pl feeded by 88.191.16.109 Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!news.dougwise.org!nntpfeed.proxad.net!nospam.fr.eu.org!talisker.lacave.net!lacave.net!not-for-mail From: Kaye Ng Newsgroups: comp.lang.ruby Subject: basic ENCAPSULATION help Date: Wed, 30 Mar 2011 04:33:00 -0500 Organization: Service de news de lacave.net Lines: 54 Message-ID: <7ae35890c4342a71e3467ade701d3556@ruby-forum.com> NNTP-Posting-Host: bristol.highgroove.com Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: Quoted-printable X-Trace: talisker.lacave.net 1301477855 56107 65.111.164.187 (30 Mar 2011 09:37:35 GMT) X-Complaints-To: abuse@lacave.net NNTP-Posting-Date: Wed, 30 Mar 2011 09:37:35 +0000 (UTC) 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: 380590 X-Ml-Name: ruby-talk X-Rubymirror: Yes X-Ruby-Talk: <7ae35890c4342a71e3467ade701d3556@ruby-forum.com> Xref: x330-a1.tempe.blueboxinc.net comp.lang.ruby:1950 This example demonstrates the use of 'private' class Person def initialize(name) set_name(name) end def name @first_name + ' ' + @last_name end private def set_name(name) first_name, last_name =3D name.split(/\s+/) set_first_name(first_name) set_last_name(last_name) end def set_first_name(name) @first_name =3D name end def set_last_name(name) @last_name =3D name end end From the book: " private tells Ruby that any methods declared in this class from there on should be kept private. This means that only code within the object=E2=80=99s methods can access those private methods, whereas code outside of the class cannot. For example, this code no longer works " p =3D Person.new("Fred Bloggs") p.set_last_name("Smith") _________________________________________________________________________= _ NoMethodError: private method 'set_last_name' called for # _________________________________________________________________________= __ When the author says, "only code within the object=E2=80=99s methods can access those private methods, whereas code outside of the class cannot.", what is the code in the example that can "access those private methods", and what is the "code outside of the class that cannot" ? That's it for now, more questions later. Apologies to the author of this book, it's not you, it's me. I'm a really slow learner. Thanks guys! -- = Posted via http://www.ruby-forum.com/.=