Ruby not recognizing Grackle object/plugin (Twitter API wrapper) -- "NameError: uninitialized constant Grackle"

121 views Asked by At

The very first line of this program is where the error happens,

require 'grackle'

This is code I wrote this morning while I was in class and with the entire program (which starts with 'require grackle') I was able to read tweets and write them directly from the command line. Now I get home and try to run the exact same program on my mac (from irb) and get this:

source "grackle.rb"

>> require 'grackle'
NameError: uninitialized constant Grackle
 from ./grackle.rb:5
 from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:36:in `gem_original_require'
 from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:36:in `require'
 from grackle.rb:2
>> require 'json'
=> false
>> require 'highline/import'
=> false
>> 
?>  $client = Grackle::Client.new( :auth => {
...(Oauth keys)...
NameError: uninitialized constant Grackle
from grackle.rb:6
etc etc, every time Grackle gets called a similar error occurs

after it tries to run the first line. This initial error then triggers a cascade of errors.

I have installed the grackle gem. What's going on here?

1

There are 1 answers

0
Casper On BEST ANSWER

You are running ruby 1.8. You need to require 'rubygems' before you can require 'grackle' (the gem).

You are confusing yourself because you have a file named grackle.rb in your current directory, but you did not initialize rubygems in your irb first, so require 'grackle' will load the local grackle.rb instead of the gem.