我是ruby语言的新手。
我只需要执行一个用ruby写的程序。
我查看了 这个小项目. 然后看到它包含了一个gemfile,并进行了以下步骤。
# Fist installed what I believe is needed
sudo apt install ruby-full
sudo gem install bundler
cd colorscore
bundle install --path vendor/bundle
然后按照建议在 README.md
创建了一个有内容的文件。
include Colorscore
histogram = Histogram.new('test/fixtures/skydiver.jpg')
# This image is 78.8% #7a9ab5:
histogram.scores.first # => [0.7884625, RGB [#7a9ab5]]
# This image is closest to pure blue:
palette = Palette.from_hex(['ff0000', '00ff00', '0000ff'])
scores = palette.scores(histogram.scores, 1)
scores.first # => [0.16493763694876, RGB [#0000ff]]
然后执行。
bundle exec ruby Main.rb
我得到的错误是:"Main.rb:2:in `': uninitialized constant Histogram (NameError)
Main.rb:2:in `': uninitialized constant Histogram (NameError)
好像是 Main.rb
文件读取 Colorscore
模块,但不能访问 Histogram
类里面。
我到底做错了什么?
版本。
ruby -v
# ruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-linux-gnu]
bundle -v
# Bundler version 2.1.4
感谢@Olkin@BobRodes的评论,我已经解决了这个问题。
我不得不添加: require 'colorscore'
在顶部 Main.rb