I can't understand why this script
#!/usr/bin/ruby
class A
attr_accessor :vdef test
p @v
enddef mod_explicit_setter
self.v = "explicit setter"
enddef mod_setter
v = "setter"
enddef mod_direct
@v = "direct"
end
enda = A.new
p a.methods - Object.new.methodsa.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>