1

正如我在问题标题中所述,我已经在 Windows 10 64 位操作系统中安装了 Ruby 3.0 版本,并且我已经编写了这个程序以生成密码并将生成的密码复制到剪贴板(PasswordGenerator.rb):

require 'clipboard'
CHARS = ('0'..'9').to_a + ('A'..'Z').to_a + ('a'..'z').to_a + ('!'..'?').to_a
def GeneratePassword(length=16)
    return CHARS.sort_by{rand}.join[0...length.to_i]
end
Clipboard.copy (GeneratePassword 15)

而且我还安装了所有可能需要作为依赖项甚至子依赖项的必要 gem:

gem install ocra
gem install --install-dir ./gems thor ftools nokogiri rubygems clipboard

但是上面的第二个命令将所有依赖项安装在(dir of PasswordGenerator.rb)/gems/gems目录而不是(dir of PasswordGenerator.rb)/gems/文件夹中,但我忽略了这一点,因为可能gem install --install-dir由于故障而被吸了一次。

但是现在当我尝试ocra在同一目录中从 PasswordGenerator.rb 构建独立的可执行文件时,它给了我这个错误。我想要这个问题的永久解决方案,了解为什么以及如何ocra即使在构建命令中指定额外的路径时也无法添加 gemsocra PasswordGenerator.rb ./gems/gems并抛出此错误:

path/to/ruby/gems/3.0.0/gems/ocra-1.3.11/bin/ocra:693:in `block (3 levels) in find_gem_files': undefined method `relative_path_from' for nil:NilClass (NoMethodError)
        from path/to/ruby/gems/3.0.0/gems/ocra-1.3.11/bin/ocra:693:in `select'
        from path/to/ruby/gems/3.0.0/gems/ocra-1.3.11/bin/ocra:693:in `block (2 levels) in find_gem_files'
        from path/to/ruby/gems/3.0.0/gems/ocra-1.3.11/bin/ocra:685:in `each'
        from path/to/ruby/gems/3.0.0/gems/ocra-1.3.11/bin/ocra:685:in `block in find_gem_files'
        from path/to/ruby/gems/3.0.0/gems/ocra-1.3.11/bin/ocra:627:in `each'
        from path/to/ruby/gems/3.0.0/gems/ocra-1.3.11/bin/ocra:627:in `find_gem_files'
        from path/to/ruby/gems/3.0.0/gems/ocra-1.3.11/bin/ocra:755:in `build_exe'
        from path/to/ruby/gems/3.0.0/gems/ocra-1.3.11/bin/ocra:1231:in `block in <top (required)>'
4

0 回答 0