`autoload` causes an error, but` require` is not (ruby)

In my Ruby program, I am trying to lazy load the library ( crack for the curious).

If I do this:

require 'rubygems'
require 'crack'

Everything is working fine. However, when I try this:

require 'rubygems'
autoload :Crack, 'crack'

Raised LoadError. (there is no such file to download - crack)

Why is this error occurring? Is it because the “crack” (and therefore my other user-set gems) is not in my $ LOAD_PATH?

edit:

In addition, it autoloadworks with the standard library:

autoload :Yaml, 'yaml'

It works fine and does not cause errors.

+3
source share
1 answer

You need to add the “crack” gem to your $ LOAD_PATH by doing:

gem 'crack'

, RubyGems Kernel # require , "" , , , .

+5

Source: https://habr.com/ru/post/1708112/


All Articles