PromoteSelf
PromoteSelf converts a module’s class 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.
Usage
module MyModule extend PromoteSelf def self.jumble( obj, arg ) obj + arg end end class String include MyModule end MyModule.jumble( "Try", "Me" ) #=> "TryMe" "Try".jumble( "Me" ) #=> 'TryMe'
Methods
Public Instance methods
[ show source ]
# File lib/facets/more/promoteself.rb, line 49 def singleton_method_added( meth ) d = %{ def #{meth}(*args) #{self.name}.#{meth}(self,*args) end } self.class_eval d singleton_method_added_promoteself( meth ) if defined?(singleton_method_added_promoteself) end