From: Rick DeNatale Date: 2007-03-18T00:41:09+09:00 Subject: Re: attr_accessor question On 3/17/07, Corey Konrad <0011@hush.com> wrote: > how come this doesnt worh though? You don't say HOW it's not working. > > class Animal > attr_accessor :color > attr_accessor :size > > def initialize(color, size) > @color = color > @size = size > end > end > > animal = Animal.new I'm guessing that it's here, since you've defined initialize to require two parameters and you aren't supplying any. If that's the case try either animal = Animal.new("purple", "teeny-weeny") or make the arguments optional by providing defaults like: > animal.color = "brown" > puts "The color of the animal is #{animal.color}" > animal.color = "red" > puts "Now the animal is #{animal.color}" > animal.size = "big" > puts "The size of the animal is #{animal.size}" > > > > thanks > > -- > Posted via http://www.ruby-forum.com/. > > def initialize(color='transparent', size='medium') @color = color @size = size end or even def initialize(color=nil, size=nil) ... If you want to allow nil as an initial value. -- Rick DeNatale My blog on Ruby http://talklikeaduck.denhaven2.com/