Re:Better Know a Ruby Thing: Singleton Classes
by Lammy on Friday January 31, 2025 @05:52PM
(#42893313)
> What we’ve been calling “class methods” are actually instance methods of the metaclass.
This also shows up if you ever want to use a Refinement on a “class method”. The thing you must `refine` is the `singleton_class`.
Here's a live example from my UUID library where I refine `Time::now` and one of my own utility class' methods to test the time-went-backwards and network-card-changed cases for incrementing the sequence value while generating time-based UUIDs: https://github.com/okeeblow/DistorteD/blob/3e9bbc744479afd3e...
This also shows up if you ever want to use a Refinement on a “class method”. The thing you must `refine` is the `singleton_class`.
Here's a live example from my UUID library where I refine `Time::now` and one of my own utility class' methods to test the time-went-backwards and network-card-changed cases for incrementing the sequence value while generating time-based UUIDs: https://github.com/okeeblow/DistorteD/blob/3e9bbc744479afd3e...