From: John Barnette Date: 2009-04-28T07:39:54+09:00 Subject: Re: Why does attr_accessor in module require 'self.'? Hi, On Apr 27, 2009, at 3:30 PM, Brian Hartin wrote: > When a class mixes in a module containing 'attr_accessor :foo', it > must > then use 'self.foo = ...' instead of simply 'foo = ...'. While I > prefer > 'self.foo' for clarity's sake, I am stumped as to _why_ this is > required. [snip] It's because Ruby automatically creates local variables upon assignment. Given a class with a method "foo": class C attr_accessor :a def foo a = 42 # this is a local variable assignment self.a = 42 # this is a call to the "a=" method end end ~ j.