Reputation: 11904
class MyClass
def fun
puts self
end
def self.fun2
puts self
end
end
mine = MyClass.new
mine.fun
MyClass.fun2
The above code should print self twice, in which case they are both MyClass. However, the actual output is
#<MyClass:0x10f6a82d0>
MyClass
which are in two difference forms. I wonder if they are actually representing different things.
Upvotes: 1
Views: 40
Reputation: 4943
The first result is the string representation of an instance of MyClass, whereas the second result is the string representation of the class MyClass.
If you had made another mine2 = MyClass.new
and printed it, you'd get a different hex identifier at the end to distinguish it from your other instance.
Upvotes: 1
Reputation: 11436
#<MyClass:0x10f6a82d0>
represents an instance of the class MyClass
. MyClassf.fun2
returns the class itself.
Upvotes: 1