I know I can import instance_methods, but is it possible to import class methods, and how?
I know I can import instance_methods, but is it possible to import class methods,
Share
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.
A common idiom is this:
What’s with that InstanceMethods module?
When I need module to include both instance and class methods to my class, I use two submodules. This way the methods are neatly grouped and, for example, can be easily collapsed in code editor.
It also feels more “uniform”: both kinds of methods are injected from
self.includedhook.Anyway, it’s a matter of personal preference. This code works exactly the same way: