Last active
May 1, 2016 05:23
-
-
Save benolee/6e7a4c7184e5f76558b8 to your computer and use it in GitHub Desktop.
This file contains 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
def f a, b = Proc.new | |
Module.new { | |
const_set :M__, self | |
module_exec self, *a, &b | |
} | |
end | |
m1 = module f(:m1_ok) { |mod, sym| @foo = sym }::M__ | |
def foo | |
@foo | |
end | |
extend self | |
self | |
end | |
p m1.foo #=> :m1_ok | |
m2 = module f(:m2_ok, -> mod, sym { | |
extend m1 | |
@bar = sym | |
})::M__ | |
@foo = :m2_foo | |
BAR = @bar | |
self | |
end | |
p m2.foo #=> :m2_foo | |
p m2::BAR #=> :m2_ok | |
m3 = module f(:m3_ok) do |mod, sym| | |
extend m1 | |
self::FOO = sym | |
end::M__ | |
@foo = [FOO, Module.nesting] | |
self | |
end | |
p m3.foo #=> [:m3_ok, [#<Module:0x41398b90>]] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment