Module | Instantize |
In: |
lib/more/facets/instantize.rb
|
Instantize converts module methods into instance methods such that the first parameter is passed self at the instance level. This promotes DRY programming when wishing to offer both an inheritable and a module callable procedure.
module MyModule extend Instantize def self.jumble( obj, arg ) obj + arg end end class String include MyModule end MyModule.jumble( "Try", "Me" ) #=> "TryMe" "Try".jumble( "Me" ) #=> 'TryMe'
This module used to be called PromoteSelf. Instantize is more descriptive, but a better name is probably still out there.