Skip to content

Instantly share code, notes, and snippets.

@benolee
Created July 24, 2014 15:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save benolee/ed5b862e6940f0d77e53 to your computer and use it in GitHub Desktop.
Save benolee/ed5b862e6940f0d77e53 to your computer and use it in GitHub Desktop.
puts "toplevel Module nesting: #{Module.nesting.inspect}"
class Foo
def bar
puts "hello from Foo#bar"
end
end
::ExportedFoo = Foo
puts "-----> using `require`"
require "./foo"
foo = Foo.new
foo.bar
Object.send :remove_const, :Foo
Object.send :remove_const, :ExportedFoo
####
puts
puts "-----> using `load` with module wrapping"
load "./foo.rb", true
begin
foo = Foo.new
rescue
puts "can't load Foo, trying ExportedFoo"
end
foo = ExportedFoo.new
foo.bar
__END__
Result:
$ ruby main.rb
-----> using `require`
toplevel Module nesting: []
hello from Foo#bar
-----> using `load` with module wrapping
toplevel Module nesting: [#<Module:0x007f8d7b1096a8>]
can't load Foo, trying ExportedFoo
hello from Foo#bar
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment