S
Samnang Chhun
I would like to know is there any ways to check is singleton class of an
object already created?
ex: obj.singleton_class_defined?
object already created?
ex: obj.singleton_class_defined?
I would like to know is there any ways to check is singleton class of an
object already created?
ex: obj.singleton_class_defined?
object already created?
an object, whether a singleton method for that object exists or not.
I'm not sure every time we invoke 'singleton_methods', then it will
create the singleton class if it doesn't exist yet.
class Object
def singleton_class?
self.singleton_methods.length == 0 ? false : true
end
end
Really small point here, and not really on topic, but this is a little
around the houses and can be slightly improved:
class Object
=A0def singleton_class?
=A0 =A0!self.singleton_methods.empty?
=A0end
end
Or just !=3D 0, since it'll return the true/false without the need for a
ternary.
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.