I would like to know is there any ways to check is singleton class of an
object already created?
ex: obj.singleton_class_defined?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The singleton class of an object is always defined. In 1.8.7 you can use
singleton_methodsto see if an object already has associated singleton methods:1.9.2 (possibly also earlier 1.9s, I can’t remember) also has a method called
singleton_class, which saves you from doing theclass << self; self ; endthing we all got used to:Edit:
Since you tagged this with “object-model”, I also wanted to recommend the following link:
http://www.hokstad.com/ruby-object-model.html
To quote from there: