3 Matching Annotations
- Apr 2021
It seems inelegant to me to split this into two different modules, one to include, the other to extend.
the key thing (one of them) to understand here is that: class methods are singleton methods
Trust this answer. This is a very common idiom in Ruby, solving precisely the use case you ask about and for precisely the reasons you experienced. It may look "inelegant", but it's your best bet.
- programming idiom
- depends on how you look at it
- Ruby: modules
- "trust us"
- Ruby: class methods
- Ruby: singleton methods
- programming languages: learning/understanding the subtleties
When we usedef self.method, though, we are defining a method across scopes: we are present in the regular class scope, but we use Ruby’s ability to define methods upon specific instances from anywhere; self within a class definition is the Class instance we are working on (i.e. the class itself). Therefore, usingdef self.method is a leap to another scope, and this feels wrong to me.