Sunday, 7 September 2014

Nested Modules in Ruby

module Dojo
  A = 4
  module Kata
    B = 8
    module Roulette
      class ScopeIn
        def push
          var1=15
        end
      end
    end
  end
end

A = 16
B = 23
C = 42

puts "Local Variable- A : #{A}"
puts "Dojo::A - #{Dojo::A}"

puts "B - #{B}"
puts "Dojo::Kata::B - #{Dojo::Kata::B}"

puts

puts "C - #{C}"
puts "Dojo::Kata::Roulette::ScopeIn.new.push - #{Dojo::Kata::Roulette::ScopeIn.new.push}"


Output:
Local Variable- A : 16
Dojo::A - 4
B - 23
Dojo::Kata::B - 8

C - 42
Dojo::Kata::Roulette::ScopeIn.new.push - 15

No comments:

Post a Comment