Created
November 19, 2020 06:50
-
-
Save drwl/d7241228e74d7c93a839c2e703665a4e to your computer and use it in GitHub Desktop.
example of autoload not playing well
This file contains hidden or 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
# ~/workspace/autoload-example ls -l | |
# total 24 | |
# -rw-r--r-- 1 andrew.lee 588821037 86 Nov 18 22:42 mod.rb | |
# -rw-r--r-- 1 andrew.lee 588821037 94 Nov 18 22:47 not-working.rb | |
# -rw-r--r-- 1 andrew.lee 588821037 76 Nov 18 22:45 works.rb | |
# mod.rb | |
module Mod | |
class Foo | |
def self.call | |
puts 'hi this works' | |
end | |
end | |
end | |
# works.rb | |
$LOAD_PATH << File.expand_path(__dir__) | |
autoload :Mod, 'mod' | |
Mod::Foo.call | |
# ruby works.rb | |
# | |
# hi this works | |
# not-working.rb | |
$LOAD_PATH << File.expand_path(__dir__) | |
module Mod; end | |
autoload :Mod, 'mod' | |
Mod::Foo.call | |
# ruby not-working.rb | |
# | |
# Traceback (most recent call last): | |
# not-working.rb:7:in `<main>': uninitialized constant Mod::Foo (NameError) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment