Instantise
Instantise 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 Instantise def self.jumble( obj, arg ) obj + arg end end class String include MyModule end MyModule.jumble( "Try", "Me" ) #=> "TryMe" "Try".jumble( "Me" ) #=> 'TryMe'
Notes
This module used to be called PromoteSelf. Instantise is more descriptive, but a better name is probably still out there.
Methods
Public Class methods
[ show source ]
# File lib/more/facets/instantise.rb, line 77 def self.append_features(mod) mod.extend self end
Public Instance methods
[ show source ]
# File lib/more/facets/instantise.rb, line 81 def singleton_method_added( meth ) d = %{ def #{meth}(*args) #{self.name}.#{meth}(self,*args) end } self.class_eval d super(meth) end