My Gemfile:
gem "toml-rb", "~> 0.3.8"
*.rb file:
require "toml-rb"
Locally it works, on a remote server - error:
/home/user_123/.rubies/ruby-2.4.2/lib/ruby/2.4.0/rubygems/core_ext/kernel_require.rb:55:in `require': cannot load such file -- toml-rb (LoadError)
Although I've run "bundle" and
$ bundle info toml-rb
* toml-rb (0.3.15)
Summary: TOML parser in ruby, for ruby.
Homepage: http://github.com/emancu/toml-rb
Path: /home/user_123/.gem/ruby/2.4.2/gems/toml-rb-0.3.15
What's the matter?
It looks like you're using v0.3.15 of toml-rb. At that point, it was referred to simply as toml.
Try this:
require "toml"
Here's an excerpt from the README for v0.3.15:
require 'toml'
# From a file!
path = File.join(File.dirname(__FILE__), 'path', 'to', 'file')
TOML.load_file(path)
Beginning at v1.0.0, the toml-rb would be required like so: require 'toml-rb'. Here's the release where this was changed: https://github.com/emancu/toml-rb/releases/tag/v1.0.0
Related
I'm writing a gem that depends on another gem I've created.
In my host gem, I'm requiring my gem as a dependency like this:
$:.push File.expand_path('../lib', __FILE__)
Gem::Specification.new do |s|
s.require_path = "lib"
s.files = Dir["lib/**/*"]
s.test_files = Dir["spec/**/*"]
s.add_dependency "my_other_gem"
end
My gemfile looks like this:
source "http://rubygems.org"
gem 'my_other_gem' path: '../my_other_gem', require: 'my_other_gem'
gemspec
And inside the host gem, I've got a class that requires my_other_gem:
require 'my_other_gem'
In my_other_gem, inside lib/my_other_gem.rb, I've got two more require classes. So it looks like this:
require 'my_other_gem/foo'
require 'my_other_gem/bar'
When I spin up IRB in the host app and run require 'my_other_gem', I get this error
LoadError: cannot load such file -- my_other_gem
When I'm playing in the my_other_gem directory and I spin up IRB, the same require 'my_other_gem' command does not error out. Everything runs normally. But for some reason I can't require my_other_gem when I'm in my host gem.
What step am I missing?
How do you start irb? You need to run it in the bundler context with bundle exec.
I just tried and if I just run irb, I get the same error.
But if I run bundle exec irb, it works.
I have a tiny, plain (i.e. non-Rails) Ruby project that I'm trying to get to work with the addressable gem. Here's what happens:
$ ruby -r rubygems sign.rb
sign.rb:5:in `require': cannot load such file -- addressable (LoadError)
from sign.rb:5:in `<main>'
This is the Gemfile:
source "http://rubygems.org"
gem "addressable", "~> 2.3.2"
This is sign.rb:
#!/usr/bin/env ruby
require "rubygems"
require "bundler/setup"
require "addressable"
That's all there is to it. Why doesn't it want to use the gem?
There is no addressable file that you can require, just the addressable directory. You need to require the specific file under that directory you want, e.g.:
require 'addressable/uri'
uri = Addressable::URI.parse("http://example.com/path/to/resource/")
# etc ...
or
require "addressable/template"
template = Addressable::Template.new("http://example.com/{?query*}/")
# etc...
Check out the addressable docs.
Have you installed the gem previously by using $ bundle install ?
This will fetch the gems specified in your Gemfile and make them available to the working directory.
I need to reference a local gem from a plain ruby script, without installing the gem. On the trail of How to refer a local gem in ruby?, i tried creating a Gemfile with the following setup:
%w(
custom_gem
another_custom_gem
).each do |dependency|
gem dependency, :path => File.expand_path("../../#{dependency}", __FILE__)
end
and the script looks like this:
require 'custom_gem'
CustomGem::Do.something
When I execute this with:
bundle exec ruby script.rb
I get:
script.rb:1:in `require': cannot load such file -- custom_gem (LoadError) from script.rb:1:in `<main>'
If I leave out the require 'custom_gem' , I get:
script.rb:3:in `<main>': uninitialized constant CustomGem (NameError)
I even tried without bundler, and just writing gem ... :path =>̣ ... in the script itself, but without results. Is there any other way of referencing custom gems from ruby scripts, without installing the gems locally?
Make sure that your gem name as same as in Gemfile (e.g. custom_gem)
# Gemfile
source "https://rubygems.org"
gem "custom_gem", path: "/home/username/path/to/custom_gem"
Don't forget to actually install this gem using bundler
bundle install
After that, the script should be ready to use by bundle exec ruby script.rb
# script.rb
require 'custom_gem'
CustomGem::Do.something
Without using a Gemfile, you can install a local version of a gem by running bundle exec rake install in the gem's root directory and then you can reference it just like any other installed gem.
I built a gem using
$ gem build <gemspec>
It got built successfully and I successfully installed it.
but when I do the following:
$ irb -rubygems
irb(main):003:0 require 'xxxx'
I get the following error:
LoadError: no such file to load -- xxxx
from C:/Ruby187/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:36:in 'gem_original_require'
from C:/Ruby187/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:36:in 'require'
What am I doing wrong?
Can you post your .gemspec file as well?
It's quite possible that you haven't included the files in the .files array. For example,
Gem::Specification.new do |s|
# Other specifications
s.files = ["bin/google", "lib/google.rb", "lib/google/utils.rb"]
s.files += ["LICENSE.md", "README.md", "google.gemspec"]
end
my ruby environment cant see an installed gem, at least the require fails
It's about the gem wordnet http://deveiate.org/projects/Ruby-WordNet I start an example script ( as user of course )
./meronymTree.rb
./meronymTree.rb:8:in `require': no such file to load -- wordnet (LoadError)
from ./meronymTree.rb:8
In some example scripts it'S called "WordNet" and in some it's lowercase, the error is same.
here's the scripts first lines
#!/usr/bin/ruby -w
$LOAD_PATH.unshift "lib"
require 'wordnet'
Check if gem is installed, as user root
gem list |grep word
wordnet (0.0.5)
root#auedv18:/var/lib/gems/1.8/gems/wordnet-0.0.5# ls
ChangeLog convertdb.rb examples lib LICENSE rake Rakefile Rakefile.local README spec utils.rb
Other gems are fine.
I am on current ubuntu and got ruby1.8 and rubygems-1.8.6 on it, (if that makes a difference).
hm and i downloaded the wordnet-0.0.5.gem file from above site and did
gem install wordnet-0.0.5.gem
Try this:
require 'rubygems'
require 'wordnet'