Though I have gem installed I get 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 are specific to only Ruby 1.8.7 and Jruby same file works on 1.9.2. What might be broken?
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
In Ruby 1.8, the current directory is in the load path. So when you say require 'rbing', instead of using the rbing gem, Ruby will look in the current directory, see a file called rbing.rb (which is the current file), and reload it. Thus when it hits the reference to RBing, Ruby doesn't know what to do, because it was never defined. (Obviously the same thing happens for JRuby, although this may be dependent on which version you are using.) You are not seeing this error in Ruby 1.9 because the current directory is not in the load path, therefore Ruby will skip the current file and require the rbing gem.
You can confirm this by placing this line at the top of the file:
puts "#{__FILE__} was required"
Under 1.9, this should say
rbing.rb was required
Under 1.8 and JRuby, this should say
rbing.rb was required
./rbing.rb was required
(and then fail with uninitialized constant RBing).
tl;dr: Name your file something else.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With