From: Benoit Daloze Date: 2010-01-25T04:02:06+09:00 Subject: Re: Writing proper getter in a Ruby way --0016364c770f295ac2047dedb00b Content-Type: text/plain; charset=ISO-8859-1 > > Wait, why couldn't you just call accessors through 'self'? > > class Foo > attr_accessor :a, :b > def bar > self.a.to_i + 5 > end > end > > p Foo.new.bar > #=> 5 > # (no warnings) > We are in #value, to get @value ... class C attr_reader :var def var self.var || 2 end end C.new.var #=> SystemStackError: stack level too deep Anyway, we have chosen sth like: args.unshift nil if Numeric === args.first (@name, @value), @proc = args, proc And then not using the accessor of attr_* for reading. It's just a quick escape sequence from initialization. Thanks for all your answers, Regards, B.D. --0016364c770f295ac2047dedb00b--