未初始化的常量Twitter(NameError) [英] uninitialized constant Twitter (NameError)

查看:109
本文介绍了未初始化的常量Twitter(NameError)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了Twitter宝石问题.我有一个包含此内容的文件(twitter.rb)

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

当我运行文件时,出现此错误: 未初始化的常量Twitter(NameError) 我在某处的某处阅读过,那里的用户遇到了类似的问题,他通过安装新版本的ruby和rubygems解决了问题,但是我遇到的问题是运行suse 12.1并运行了最新版本的ruby和ruby gems.从任何地方的第3方都找不到rpm.我搜索过的Atleast.有人知道绕过这个问题的另一种方式吗?

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?

推荐答案

如果您运行的是Ruby 1.8.x,应该可以通过将自己的脚本重命名为不同于twitter.rb的任何名称来解决问题.

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.

这是因为twitter gem中的主文件的命名与此完全相同,并且您的文件可能会在$LOAD_PATH顺序创建的组合虚拟文件系统中覆盖它.在Ruby 1.9.x之前,require不仅从库目录加载,而且更喜欢加载相对于进程当前工作目录(在这种情况下,即脚本所在目录)的文件.

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(NameError)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆