From: Bob Hutchison Date: 2012-09-01T22:30:38+09:00 Subject: Re: Constructor or a Method Hi, On 2012-09-01, at 8:54 AM, Rubyist Rohit wrote: > @Robert, > > This is quite confusing in Ruby as method and properties look alike. You've got a terminology thing going on and this is confusing you I think. There are no such thing as 'properties' in Ruby (google it and you can read about the magical healing properties of the ruby gemstone :-) Generally speaking you've got attributes and methods. There are two kinds of attributes (class and instance) but you're talking about instance attributes. Attributes are private to an object, only the specific instance has access to them. They are idiomatically and optionally exposed to other objects through 'accessor methods' which are just methods with a naming convention, nothing at all special about them. Ruby provides three ways to concisely ask Ruby to generate accessor methods for you: attr_reader, attr_writer, attr_accessor. Idiomatic Ruby is to use these automated accessors. However, it's possible that you have something more complex you have to do in which case you'd write your own accessors. > > To correct my original post, shall I remove 'attr_accessor' to make > sense? > Since you are not doing anything special, use idiomatic Ruby: ======== [CODE] ======= def Customer attr_accessor :name end ======================= Cheers, Bob > -- > Posted via http://www.ruby-forum.com/.