I'm learning Ruby right now, and I'm confused as to why I can refer to an instance variable without the @ sigil, which would make it a local variable too. Surely the following code shouldn't work as it does:
class Test
attr_accessor :variable
def something
variable
end
def something2
@variable
end
def something3
self.variable
end
end
y = Test.new
y.variable = 10
puts y.something # => 10
puts y.something2 # => 10
puts y.something3 # => 10
I'd have expected y.something to return nil. Why do local variables and instance variables point to the same location? I'd have expected @variable and variable to have been two discrete variables.