Ruby's module_function
Problem:
You have a module of utility methods of which you only use a handful and only in your private methods. The utiltiy methods are polluting your class namespace and you are losing sleep and pulling your hair out at an alarming rate.
"Not as good" solution:
module UrlThingies def self.query_parts(url) # do thingies end private def query_parts(url) self.class.query_parts(url) end end
Now you can access your methods at both a module and instance level, but now you have to replicate every method you write twice and your therapist is concerned with your progress.
Introducing 'module_function'
module UrlThingies module_function def query_parts(url) raise "Clever Cloggs Alert" end end
With that one line of code you have both a module and instance level version of the following methods - plus! the instance methods are considered private, so your class API is left unscaved.
Phew that was a close one!













