Making class methods re-usable from modules (in Ruby)

Posted by ungraspiness Mon, 25 Jun 2007 21:56:00 GMT

module TestMod
end

def TestMod.append_features(klass)
  def klass.method
    puts "#{self}: in method" 
  end
end

class Class1
  include TestMod
end

class Class2
  include TestMod
end

Class1.method()
Class2.method()

This should work even without the authors code available.

Posted in  | Tags  | no comments

Comments

(leave url/email »)

   Comment Markup Help Preview comment