From: Gabriel Dragffy Date: 2007-08-04T05:55:18+09:00 Subject: Re: Beginner's tutorial and poor attempt at classes On 3 Aug 2007, at 19:21, dblack@rubypal.com wrote: [...SNIP...] >>> >>> def roll >>> self.number = rand(6) + 1 >>> end >> >> >> Have been rereading your example. Just wanted to ask why in the >> code just above did you use "self.number" which you changed from >> @number? >> >> >>> >>> def number=(value) >>> if (1..6).include?(value) >>> @number = value >>> else >>> puts "A die has only six sides!" >>> end >>> end >>> end >> >> and then here "@number" is used.. finding this a little confusing. >> Thanks again, for all your help. > > The number= method does some data checking, and if all is well it sets > @number. I don't want to set @number directly, because the checking > won't happen. I guess rand(6) + 1 is pretty safe, but still, since my > setter method does more than just set @number, it's "polite" to go > through that method instead of just setting @number. Hi David Thank you for your quick reply and help. I have to confess I'm being quite dumb about this, I still don't understand 100% why one should use self.number.... but I think that's something that I need to work on and all will become clear as I become more familiar with Ruby as a whole. I've bought on Amazon a book called Beginning Ruby, dunno if it's any good, but I should received it tomorrow (fingers crossed!) so I can study it over the weekend. My full time job is a web programmer, I've got a couple of large projects coming up, and because my boss is cool I can use any language/framework I like. Naturally I've chosen Rails.... I hope to get my Ruby up to speed for this, and I'll be needing a good RoR book. I see that you yourself have authored some books. That's awesome! Do you think your rails books would fit my needs? Also, is there anywhere I can view several pages from it? Best regards Gabriel Dragffy gabe@dragffy.com