This does not output anything:
class Test
attr_accessor :value
def run
set_value
puts value
end
def set_value
value = 6 # No 'self'
end
end
Test.new.run
Whereas this outputs '6'
class Test
attr_accessor :value
def run
set_value
puts value
end
def set_value
self.value = 6 # With 'self'
end
end
Test.new.run
Why do I need self
when the method is defined already? Surely Ruby should use the method rather than creating a local variable in the set_value function?