From: Rob Biedenharn Date: 2012-12-11T08:50:50+09:00 Subject: Re: Need a little help On Dec 10, 2012, at 6:28 PM, tom mr wrote: > Hey Guys, > New to ruby & working on a few tutorials & I'm having trouble with > getting the following code to work & I can't figure out why? > > class Animal > attr_accessor :name > attr_writer :color > attr_reader :legs, :arms > > def setup_limbs > @legs = 4 > @arms = 0 > end > > def noise=(noise) > @noise = noise > end This sets @noise, but there's no method for getting the noise back. You probably need to add either: attr_reader :noise (or just att , :noise following the :legs, :arms in the earlier one) Or define your own getter like was done for color. -Rob > > def color > "The color is #{@color}." > end > end > > animala = Animal.new > animala.setup_limbs > animala.noise = "Moo!" > animala.name = "Steve" > puts animala.name > animala.color = "black" > puts animala.color > puts animala.legs > puts animala.noise > > animalb = Animal.new > animalb.noise = "Quack!" > puts animalb.noise > > I've double checked the tutorial (video) & every piece seems to be > correct but where the tutorial works in the video I can't! > > Thanks, > Tom > > -- > Posted via http://www.ruby-forum.com/. >