on-internet
← Community

Simultaneously creating instance and class methods with the same name in a ruby class

Stack Overflow ·

Is there a way for me to simultaneously create a class and an instance method in a ruby class that have the same name? I have a version of this created in the class Foo class Foo def self.bar "hello world" end def bar self.class.bar end end While this works, is there a more elegant way of achieving this? Right now, I would have to duplicate ~10 methods as instance and class methods.

Comments

Sign in or sign up to comment and upvote.

No comments yet.