From: trebor777 Date: 2007-10-27T20:22:39+09:00 Subject: Re: find all member in a class THUFIR HAWAT wrote: > > On Fri, 26 Oct 2007 20:58:01 +0900, Rick DeNatale wrote: > > >> class A >> def i >> @i ||= 42 >> end > > > Some rudimentary explanation please: > > the def is to define a method? > it's a coincidence that the method name is "i" and the instance variable > has the same name, "I"? > > > the third line declares an instance variable, "i", what do the "||" do in > that line, please? > > > > thanks, > > Thufir > > > > Yeap "def" is to define a method It could be a coincidence... or not, depends on what you want to do with this method... hum Here it's not a coincidence... this method return the value of the instance variable i (it's a reader accessor) or if it's nil, set it to 42 and return it. basically || means "if it's nil do that ", then = assigns the value 42 to @i -- View this message in context: http://www.nabble.com/find-all-member-in-a-class-tf4695579.html#a13442171 Sent from the ruby-talk mailing list archive at Nabble.com.