Created
December 12, 2012 14:04
-
-
Save wanabe/4267936 to your computer and use it in GitHub Desktop.
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 characters
| module Foo | |
| C1 = 1 | |
| class << self | |
| C2 = 2 | |
| ::IFoo = self | |
| end | |
| end | |
| module Bar | |
| C3 = 3 | |
| class << Foo | |
| C4 = 4 | |
| def hoge | |
| [defined?(C1), defined?(C2), defined?(C3), defined?(C4)].map {|b| b ? 1 : 0}.join | |
| end | |
| define_method(:fuga) do | |
| [defined?(C1), defined?(C2), defined?(C3), defined?(C4)].map {|b| b ? 1 : 0}.join | |
| end | |
| end | |
| def Foo.piyo | |
| [defined?(C1), defined?(C2), defined?(C3), defined?(C4)].map {|b| b ? 1 : 0}.join | |
| end | |
| IFoo.send(:define_method, :hogera) do | |
| [defined?(C1), defined?(C2), defined?(C3), defined?(C4)].map {|b| b ? 1 : 0}.join | |
| end | |
| end | |
| p [Foo.hoge, Foo.fuga, Foo.piyo, Foo.hogera] | |
| mod = Foo.dup | |
| p [mod.hoge, mod.fuga, mod.piyo, mod.hogera] | |
| # ruby 1.8.7 (2012-02-08 patchlevel 358) [x86_64-linux] | |
| # ["0111", "0111", "0010", "0010"] | |
| # ["1010", "0111", "1000", "0010"] | |
| # ruby 1.9.3p194 (2012-04-20 revision 35410) [x86_64-linux] | |
| # ["0111", "0111", "0010", "0010"] | |
| # ["0111", "0111", "0101", "0010"] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment