From: Tanner Burson Date: 2006-05-06T07:20:15+09:00 Subject: Rough idea regarding modification of core classes ------=_Part_24986_28830790.1146867611647 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: quoted-printable Content-Disposition: inline After reading the sharp knives and glue thread, my head started spinning around some ways to minimize or localize the modifications to core classes. This is what I came up with, it's obviously rough, not-all-inclusive, and has some fairly obvious and severe drawbacks, but none-the-less I thought I'd share my 20 minutes of fiddling in the hopes of sparking some conversation if nothing else. class Object def define_meta_methods(name,&blk) @@__meta_methods__=3D (Object.class_variables.include?("@@__meta_methods") ? @@__meta_methods__ : Hash.new) @@__meta_methods__[name] =3D Array.new if @@__meta_methods__[name].nil? @@__meta_methods__[name] << blk end def add_meta_methods @@__meta_methods__[self.class].each do |mm| instance_eval &mm end end end Object.define_meta_methods(String) do def test_meta puts "Tested Meta!" end end Object.define_meta_methods(String) do @something=3D"Hello" def something; @something; end; # had to go this route instead of attr_reader, because of private restriciton. Can avoid it with the send hack though. end some_string =3D String.new some_other_string =3D String.new some_string.add_meta_methods some_string.test_meta # -> "Tested Meta!" puts some_string.something # -> "Hello" some_other_string.test_meta #--> "No method error" -- =3D=3D=3DTanner Burson=3D=3D=3D tanner.burson@gmail.com http://tannerburson.com <---Might even work one day... ------=_Part_24986_28830790.1146867611647--