I am pretty new to Ruby and have learned it syntax along with singleton methods. I understand how to create and use them. But why use them?
Can someone give me a few real world cases where using singleton methods are helpful?
Thank You
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.
Maybe you want to do some debugging? Say you have a collection of objects, and you know one of them acts up while being iterated over alongside it’s siblings… so you modify a problematic method to wrap it in some logging / tracing code that saves you having to read pages of logging statements for the 100 other items.
That’s at least one contrived example I can think of.