简体   繁体   中英

Fresh Ruby gem from Bundler - cannot load my version.rb file?

I wanted to make a fresh Ruby app, so I decided to use bundle gem foo to do it. This gave me the whole:

lib/
  foo/
    version.rb
  foo.rb
Gemfile
Rakefile
foo.gemspec
README.md

structure. Now when I run ruby foo.rb , I get:

`require': cannot load such file -- foo/version (LoadError)

foo.rb is just the default:

require 'foo/version'

module Foo
end

Can gems not be ran on their own? I hope I don't have to include my gem into a sample app just to test it out?

You need to run bundle exec ruby foo.rb to use Bundled gems.

Alternatively, you can modify foo.rb itself to assume Bundler. Just put

require 'bundler/setup'

at the top.

What directory are you running that from? I would check your $LOAD_PATH and ensure lib is included in it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM