class Test
class << self
attr_accessor :some
def set_some
puts self.inspect
some = 'some_data'
end
def get_some
puts self.inspect
some
end
end
end
Test.set_some => Test
puts Test.get_some.inspect => Test nil
Here above, I could find myself as a test itself, but did not return a result some_data.
But so far I have changed as follows, it returns the expected result
class Test
class << self
attr_accessor :some
def set_some
puts self.inspect
self.some = 'some_data'
end
def get_some
puts self.inspect
self.some
end
end
end
Test.set_some => Test
puts Test.get_some.inspect => Test some_data
What are the differences?
EDIT
Now in the first example, if I set the get method someas
Test.some = 'new_data'
puts Test.some.inspect
Test.set_some
puts Test.get_some.inspect => new_data
Now it has made me much more confused.
source
share