DEV Community

pooyaalamdari
pooyaalamdari

Posted on

scope variable

module M 
    class C
        class D
            module N
                X = 1
            end
        end
    end
end

puts M::C::D::N::X
Enter fullscreen mode Exit fullscreen mode
module M 
    class C
        X = 222
        class D
            module N
                X = 1
            end
        end
    end
end

puts M::C::D::N::X
puts M::C::X
Enter fullscreen mode Exit fullscreen mode

it works correct

module M 
    class C
        class D
            module N
                X = 1
            end
        end
        puts D::N::X
    end
end
Enter fullscreen mode Exit fullscreen mode

this is wrong and doesn't work!

module M 
    class C
        class D
            module N
                X = 1
            end
        end
    end
end

puts D::N::X # it is wrong 
Enter fullscreen mode Exit fullscreen mode

Top comments (0)