From: Dave Thomas Date: 2001-03-06T06:11:53+09:00 Subject: [ruby-talk:12060] Re: RCR: shortcut for instance variable initialization "Christoph Rippel" writes: > class Whatever > > def will_be_rounded=(number) > raise 'Not a number' unless kind_of? Numeric > @will_be_number = number.round > end > > def initialize(will_be_rounded@) > ... > end > attr_accessor :will_be_rounded > end > > does a call to initialize invoke ``@will_be_rounded='' > or```will_be_rounded=''? There is no such method as '@will_be_rounded='. The attr_accessor call will overwrite the method you defined with it's own: class Dave def val=(n) puts "in my val" @val = 123 end attr_accessor :val end d = Dave.new d.val = 432 p d.val #=> 432 > Ps. I sometimes wonder if Ruby could have done without > variables at all (I believe this) and only use attributes > but this is a different matter. Attributes are simply accessor functions to instance variables. Dave