Created
January 4, 2010 16:00
-
-
Save fronx/268611 to your computer and use it in GitHub Desktop.
Revisions
-
fronx renamed this gist
Jan 4, 2010 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
fronx revised this gist
Jan 4, 2010 . 1 changed file with 4 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,3 +1,5 @@ # Reincarnation for classes class Class def reincarnate buried = Object.__send__(:remove_const, self.name) @@ -22,6 +24,8 @@ def foo Abc.new.foo # Reincarnation for modules class Module def reincarnate buried = Object.__send__(:remove_const, self.name) -
fronx revised this gist
Jan 4, 2010 . 1 changed file with 28 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -20,3 +20,31 @@ def foo end Abc.new.foo class Module def reincarnate buried = Object.__send__(:remove_const, self.name) Object.const_set(self.name, Module.new).__send__(:include, buried) end end module Boo def bar "bar" end end Boo.reincarnate module Boo def bar puts super end end class BooTest include Boo end BooTest.new.bar -
fronx revised this gist
Jan 4, 2010 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,7 +1,7 @@ class Class def reincarnate buried = Object.__send__(:remove_const, self.name) Object.const_set(self.name, Class.new(buried)) end end -
fronx revised this gist
Jan 4, 2010 . 1 changed file with 7 additions and 30 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,45 +1,22 @@ class Class def reincarnate buried = Object.__send__(:remove_const, self.name) Object.const_set(:Abc, Class.new(buried)) end end class Abc def foo "foo" end end Abc.reincarnate class Abc def foo puts super end end Abc.new.foo -
fronx revised this gist
Jan 4, 2010 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -4,7 +4,7 @@ def bury(class_or_module_name) end end # Example for class self inheritance class Abc def foo @@ -21,7 +21,7 @@ def foo Abc.new.foo # Example for module self inheritance module Xyz def bar -
fronx created this gist
Jan 4, 2010 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,45 @@ class Object def bury(class_or_module_name) Object.instance_eval { remove_const class_or_module_name.to_sym } end end # Example for class "self inheritance" class Abc def foo "foo" end end class Abc < bury(:Abc) def foo puts super end end Abc.new.foo # Example for module "self inheritance" module Xyz def bar "bar" end end BuriedXyz = bury(:Xyz) module Xyz include BuriedXyz def bar puts super end end class XyzTest include Xyz end XyzTest.new.bar