Last active
June 19, 2016 03:22
-
-
Save 100lp/4740204 to your computer and use it in GitHub Desktop.
If you prepend a constant with :: without a parent, the scoping happens on the topmost level. In this exercise, change push to return 10 as per A = 10 in the topmost level, outside the Kata module.module Kata
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
module Kata | |
A = 5 | |
module Dojo | |
B = 9 | |
A = 7 | |
class ScopeIn | |
def push | |
ScopIn::A # (why if i write just "::A" - it work too ?) | |
end | |
end | |
end | |
end | |
A = 10 | |
======================= | |
Kata::Dojo::ScopeIn.new.push should return 10 |
::A returns 10, indeed. Rubymonk (where the task was taken from) doesn't let you pass, though.
@rookie , if you want to have the test pass.
module Kata
A = 5
module Dojo
B = 9
A = 7
class ScopeIn
def push
10
end
end
end
end
A = 10
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Big thanks to this, deeambler!!