Ruby get reference to a singleton class of object
class Object
class << self
def self_class
self
end
end
def singleton_class
class << self
self
end
end
end
a = [1,2,3]
p a
puts Array.self_class
puts a.singleton_class
E:\>ruby singleton_class.rb
[1, 2, 3]
Array
#<Class:#<Array:0x294053c>>
No comments :
Post a Comment