Skip to content

Instantly share code, notes, and snippets.

@evaldasg
Forked from drbrain/nesting.rb
Created January 15, 2018 16:03
Show Gist options
  • Save evaldasg/5db9bd7d3dc4b0a781e88d2bd9e8ec14 to your computer and use it in GitHub Desktop.
Save evaldasg/5db9bd7d3dc4b0a781e88d2bd9e8ec14 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