Skip to content

Instantly share code, notes, and snippets.

@drbrain
Created January 12, 2018 19:23
Show Gist options
  • Save drbrain/77717df191b79f4b349bca6fe27e4a17 to your computer and use it in GitHub Desktop.
Save drbrain/77717df191b79f4b349bca6fe27e4a17 to your computer and use it in GitHub Desktop.
module A
module B
puts "module B inside module A nesting: #{Module.nesting}"
module_function
def show_nesting
puts "show_nesting nesting: #{Module.nesting}"
end
def yielder
yield
end
end
end
module A::B
puts "module A::B nesting: #{Module.nesting}"
end
A::B.show_nesting
A::B.yielder do
puts "A::B.yielder nesting: #{Module.nesting}"
end
include A::B
show_nesting
yielder do
puts "toplevel.yielder nesting: #{Module.nesting}"
end
module B inside module A nesting: [A::B, A]
module A::B nesting: [A::B]
show_nesting nesting: [A::B, A]
A::B.yielder nesting: []
show_nesting nesting: [A::B, A]
toplevel.yielder nesting: []
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment