I can't understand why this script | #!/usr/bin/ruby | class A | attr_accessor :v | | def test | p @v | end | | def mod_explicit_setter | self.v = "explicit setter" | end | | def mod_setter | v = "setter" | end | | def mod_direct | @v = "direct" | end | end | | a = A.new | p a.methods - Object.new.methods | | a.mod_setter; a.test | a.mod_direct; a.test | a.mod_setter; a.test | a.mod_explicit_setter; a.test have this output | ["mod_setter", "mod_direct", "v", "v=", "mod_explicit_setter", "test"] | ./vm.rb:7: warning: instance variable @v not initialized | nil <- correct, v is a local variable | "direct" <- correct | "direct" <- correct? v= is an already seen method | "explicit setter" <- correct I thought that, once ruby sees a methods, it prefers to call that method instead of creating a new local variable. -- Gioele <dev / gioelebarabucci.com>