Custom_require.rb: 36: in `gem_original_require '

Although I have gem installed, I am getting the following error

/rbing.rb:4: uninitialized constant RBing (NameError)
from /Users/bhushan/.rvm/rubies/ruby-1.8.7-p352/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:36:in `gem_original_require'
from /Users/bhushan/.rvm/rubies/ruby-1.8.7-p352/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:36:in `require'
from rbing.rb:3

      

And this error is specific only Ruby 1.8.7

and Jruby

the same file is working on 1.9.2

. What can be violated?

The rbing.rb file looks like this:

require 'rubygems'
require 'rbing'
bing = RBing.new("APPID")

rsp = bing.web('infosys', :site => "linkedin.com")
puts rsp.web.results[0].url

      

+3


source to share


1 answer


In Ruby 1.8, the current directory is in the download path. So when you say require 'rbing'

, instead of using the rbing gem, Ruby will look in the current directory, see the rbing.rb file (which is the current file) and reload it. Thus, when it makes a reference RBing

, Ruby doesn't know what to do because it was never defined. (Obviously, the same happens for JRuby, although it may depend on which version you are using.) You don't see this error in Ruby 1.9 because the current directory is not in the download path, so Ruby will skip the current file and gem rbing required.

You can confirm this by placing this line at the top of the file:

puts "#{__FILE__} was required"

      

Before 1.9, that should say

rbing.rb was required

      



In section 1.8 and JRuby it should say

rbing.rb was required
./rbing.rb was required

      

(and then crashing with uninitialized constant RBing

).

tl; dr: Name your file something else.

+1


source







All Articles