Created
May 25, 2018 07:35
-
-
Save serradura/a521341187ef340b33f9347e9ff3596d to your computer and use it in GitHub Desktop.
Constant resolution in Ruby (http://valve.github.io/blog/2013/10/26/constant-resolution-in-ruby/)
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 | |
A = 1 | |
B = 2 | |
def a1 | |
A | |
end | |
def b1 | |
B | |
end | |
end | |
module Bar | |
A = 3 | |
B = 4 | |
def a2 | |
A | |
end | |
def b2 | |
B | |
end | |
end | |
class Test | |
include Foo | |
include Bar | |
end | |
p Test.constants # => [:A, :B] | |
p Test.new.a1 # => 1 | |
p Test.new.b1 # => 2 | |
p Test.new.a2 # => 3 | |
p Test.new.b2 # => 4 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment