Module extend self Discussion
This is such a handy feature of Ruby. I was amazed when I first learned about it. Really makes modules useful for any situation, not just being included in another object.
It’s one of those things that makes the language feel really flexible and elegant. Modules aren’t just for mixing in functionality—they can completely change how you structure your code, making it cleaner and more reusable.
Personally I find it confusing that by extend self module methods are duplicated in singleton class. It's cleaner to just write this way:
module CurrencyFormatter
class << self
def format(*)
# ...
end
end
end
Here the intent is clear – you have to just use this module as CurrencyFormatter.format(...), you cannot include it.