From: Intransition Date: 2011-12-26T13:48:52+09:00 Subject: Mixin for Mixins ------=_Part_455_16535729.1324874930213 Content-Type: multipart/alternative; boundary="----=_Part_456_18199749.1324874930213" ------=_Part_456_18199749.1324874930213 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Going through some old code snippets and came across this clever bit. Back then I was planning to use this for Facets, before I finally determined that using mixins wasn't actually the best approach for a core extensions library. module Extension def self.included(base) name = base.name.split('::').last core = eval("::#{name}") core.send(:include, base) end end Example: module Facets module String include Extension def drippy puts "Drippy #{self}" end end end "Hello".drippy Just thought I'd share. ------=_Part_456_18199749.1324874930213 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
Going through some old code snippets and came across this clever bit. = Back then I was planning to use this for Facets, before I finally determine= d that using mixins wasn't actually the best approach for a core extensions= library.

  module Extension
&n= bsp;   def self.included(base)
      name= =3D base.name.split('::').last
      core =3D eva= l("::#{name}")
      core.send(:include, base)
    end
  end

= Example:

    module Facets
&nb= sp;     module String
        inclu= de Extension

        def dripp= y
          puts "Drippy #{self}"
<= div>        end
      end
    end

    "Hello".drip= py

Just thought I'd share.

------=_Part_456_18199749.1324874930213-- ------=_Part_455_16535729.1324874930213--