From: "Sebastjan H." Date: 2012-10-03T02:56:26+09:00 Subject: Re: still learning by doing - connecting rooms in a game Jan E. wrote in post #1078392: > Sebastjan H. wrote in post #1078385: >> I tried this and I removed the attr_accessor line and had the methods >> defined, but then the code doesn't work: > > What do you mean by "doesn't work"? The class does exactly what it > should: > > zombie = Zombie.new 'some_name', 'some_hp', 'some_paces', 'some_target' > p zombie > puts zombie.name > > Note that you do *not* have writer methods, so you cannot do something > like > > zombie.name = 'newname' > > Anyway, the right way to do this is to use attr_accessor. That's what I meant. I guess it wasn't clear from my initial code that I need writer, that is accessor. Sorry if I confused anyone. It's just that I didn't want any duplication as Peter suggested, but then If I understand correctly I need either the writer or accessor to be able to change the values of instance variables. What I meant was, that if omit the attr_accessor completely and only have methods for instance variables defined, then player.hp -=20 does nothing. regards seba -- Posted via http://www.ruby-forum.com/.