------ art_455_16535729.1324874930213
Content-Type: multipart/alternative;
boundary --- art_456_18199749.1324874930213"
------ art_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 ase.name.split('::').last
core val("::#{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.
------ art_456_18199749.1324874930213
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div>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 extensionsibrary.</div><div><br></div><div> module Extension<br></div><div> def self.included(base)<br></div><div> name3D base.name.split('::').last</div><div> core = eval("::#{name}")</div><div> core.send(:include, base)</div><div> end</div><div> end<br></div><div><br></div><div>Example:</div><div><br></div><div> module Facets</div><div> module String</div><div> include Extension</div><div><br></div><div> def drippy</div><div> puts "Drippy #{self}"</div><div> end</div><div> end</div><div> end</div><div><br></div><div> "Hello".drippy</div><div><br></div><div>Just thought I'd share.</div><div><br></div>
------ art_456_18199749.1324874930213--
------ art_455_16535729.1324874930213--