Created
July 24, 2014 15:08
-
-
Save benolee/ed5b862e6940f0d77e53 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
puts "toplevel Module nesting: #{Module.nesting.inspect}" | |
class Foo | |
def bar | |
puts "hello from Foo#bar" | |
end | |
end | |
::ExportedFoo = Foo |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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