Hey guys i have a problem i am facing with the twitter gem. I have a file (twitter.rb) with this content
require "rubygems"
require "twitter"
puts Twitter.user_timeline("roykasa").first.text
puts Twitter.user("roykasa").location
search = Twitter::Search.new
search.containing("hate").to("StewieJokess").
result_type("recent").each do |r| puts r.text end
When i run the file i get this error : uninitialized constant Twitter (NameError) I read somewhere on SO where a user had a similar problem and he solved it by installing a new version of ruby and rubygems but the problem i am having is am running suse 12.1 and am running the latest versions of both ruby and ruby gems. No rpms can be found from 3rd parties anywhere. Atleast i have searched. Does anyone know another way round this?
If you are running Ruby 1.8.x you should be able to solve your problem by renaming your own script to anything different than twitter.rb
.
This is because the main file in the twitter
gem is named exactly like this and your file probably overrides it in combined virtual file system that the $LOAD_PATH
order creates. Before Ruby 1.9.x, require
did not only load from library directories, but preferred to load files relative to the current working directory of your process, in this case, the directory where your script lies in.
不要将文件命名为twitter.rb ,也请确保同一目录中没有其他文件名为twitter.rb。
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.