From: Phrogz Date: 2007-03-18T08:15:05+09:00 Subject: Re: attr_accessor question On Mar 17, 9:50 am, Corey Konrad <0...@hush.com> wrote: > ah ok i understand that i am just learning all this OO stuff i just > thought i needed to use the initialize method but i dont even need to > create one for a default object state at all i can just do this as well > and the program worked fine, > > class Animal > attr_accessor :color > attr_accessor :size > end > > that is pretty cool i'm having a fun time learning this language > compared to something like vb.net. Ruby also has a nice class named Struct for easily creating classes (or starting them off) that are just piles of optional attributes by name: [sliver:~] gkistner$ irb irb(main):001:0> Animal = Struct.new( :color, :size ) => Animal irb(main):002:0> a1 = Animal.new => # irb(main):003:0> a1.color => nil irb(main):004:0> a1.color = :blue => :blue irb(main):005:0> a1 => # irb(main):006:0> a2 = Animal.new( :orange ) => # irb(main):007:0> a3 = Animal.new( :red, 42 ) => # irb(main):008:0> a3.size = 50 => 50 irb(main):009:0> a3 => #