From: Yohanes Santoso Date: 2002-11-16T07:26:02+09:00 Subject: Re: Newbie questions regarding getter/setter methods... christopher.j.meisenzahl@citicorp.com writes: > class Song > attr_reader :name, :artist, :duration > end expands to: > class Song > def name > @name > end > def artist > @artist > end > def duration > @duration > end > end > Do I also have to declare @name, @artist, and @duration within the > method? Or are they implicitly declared by declaring the accessor > methods? You don't have to. Ruby use a first-use policy for variables. Meaning it's declared and defined when Ruby first encounter the variable. Or if you like you can do: attr :name, :artist, :duration which will simply declare them (mostly for documentation purposes). > In general, how do member variables work? Are they all private and > require accessor/reader methods to be accessed at all? My background > includes a little bit of C/C++ and Java. They are all private to outsider (not subclasses). To make them public, you have to either attr_reader or attr_writer or attr_accessor them. Expriment with irb. It's the handiest tool to explore ruby. YS.