问题描述
限时送ChatGPT账号..我正在使用 Ruby Twitter gem.我想打电话给 retweeted_by_user(user, options = {}).如何创建对象实例来调用此方法.是实例方法,对吗?
I am using the Ruby Twitter gem. I want to call retweeted_by_user(user, options = {}). How do I create instance of object to call this method. It is instance method, correct?
我是为 Twitter::REST::CLIENT 做的
I did this for Twitter::REST::CLIENT
client = client = Twitter::REST::Client.new do |config|
config.consumer_key = "..."
config.consumer_secret = "..."
config.access_token = "..."
config.access_token_secret = "..."
end
但它不适用于 Twitter::Tweet
but it does not work for Twitter::Tweet
client = client = Twitter::Tweet.new do |config|
config.consumer_key = "..."
config.consumer_secret = "..."
config.access_token = "..."
config.access_token_secret = "..."
end
推荐答案
1) 您发布的代码与调用 retweeted_by_user() 有什么关系?
1) What does the code you posted have to do with calling retweeted_by_user()?
2) 我想打电话给 retweeted_by_user(user, options = {}).如何创建对象实例来调用此方法.是实例方法,对吗?
如果您访问 twitter gem 网站:
If you go to the twitter gem website:
https://github/sferik/twitter
...然后点击文档链接,它会带你到这里:
...then click on the Documentation link, it takes you here:
http://rdoc.info/gems/twitter
...然后,如果您单击右上角的Method List
,然后向下查看 retweeted_by_user() 的列表,然后单击该链接,它会将您带到此处的方法定义:
...then if you click on Method List
in the upper right corner, and look down the list for retweeted_by_user(), and click on that link, it takes you to the method definition here:
http://rdoc.info/gems/twitter/Twitter/REST/时间线#retweeted_by_user-instance_method
...然后,如果您滚动到该页面的顶部,您可以看到该方法定义在一个名为:
...then if you scroll to the top of that page, you can see that the method is defined in a module called:
Twitter::REST::Timelines
在 ruby 中,模块包含在一个类中,然后该类的实例可以调用模块中定义的(实例)方法.哪些类包括 Twitter::REST::Timelines 模块?在页面顶部它说:
In ruby, modules are included in a class, and then instances of that class can call the (instance)methods defined in the module. What classes include the Twitter::REST::Timelines module? At the top of the page it says:
包含在:API
如果您点击 API 链接,它会将您带到此处:
If you click on the API link, it takes you here:
http://rdoc.info/gems/twitter/Twitter/REST/API
并且在该页面的顶部显示Module: Twitter::REST::API
.
and at the top of that page it says Module: Twitter::REST::API
.
好的,一个模块也可以包含另一个模块,这意味着就好像包含模块本身定义了包含模块中的方法.但是我们仍然需要在某处找到一个包含该模块的类,并且在页面顶部的 Module: Twitter::REST::API
下,它说 Included in:Client代码>,如果您单击客户"链接,则会将您带到此处:
Okay, a module can also include another module, which means it's as if the including module itself defines the methods in the included module. But we still need to find a class somewhere that includes that module, and at the top of the page under Module: Twitter::REST::API
, it says Included in:Client
, and if you click on the Client link, it takes you here:
http://rdoc.info/gems/twitter/Twitter/REST/Client
并且该页面显示 Class: Twitter::REST::Client
...这意味着 Twitter:REST::Client 类的对象可以调用方法 retweeted_by_user(),所以你可以这样写:
and that page says Class: Twitter::REST::Client
...and that means that objects of the class Twitter:REST::Client can call the method retweeted_by_user(), so you can write something like this:
results = Twitter::REST::Client.new.retweeted_by_user(....)
事实上,在记录 Twitter::REST::Client 的页面上,有一个名为 Instance Methods 的标题,如果您向下滚动方法列表,文档会显示来自包含模块的所有实例方法,例如
In fact, on the page documenting Twitter::REST::Client, there is a heading called Instance Methods, and if you scroll down the list of methods the docs show all the instance methods that come from included modules, e.g.
Methods included from Timelines: #home_timeline, #mentions_timeline,
#retweeted_by_me, #retweeted_by_user, #retweeted_to_me,
#retweets_of_me, #user_timeline
关于您的代码:
client = client = Twitter::REST::Client.new do |config|
config.consumer_key = "..."
config.consumer_secret = "..."
config.access_token = "..."
config.access_token_secret = "..."
end
文档是关于 Twitter::REST::Client.new() 的,
the docs say this about Twitter::REST::Client.new(),
构造函数详细信息
该类继承了 Twitter::Client 的构造函数
This class inherits a constructor from Twitter::Client
如果您点击 Twitter::Client 链接,它会显示:
If you click on the Twitter::Client link, it says:
- (Twitter::Client) initialize(options = {}) {|_self| ... }
这意味着:如果你调用 Twitter::REST:Client.new() 并指定一个带一个参数的块,ruby 会将新的 Twitter::Rest::Client 实例传递给该块,然后你可以在该对象上调用 retweeted_by_user(),例如:
What that means is: if you call Twitter::REST:Client.new() and you specify a block with one parameter, ruby will pass the new Twitter::Rest::Client instance to the block, and then you can call retweeted_by_user() on that object, e.g.:
Twitter::REST::Client.new do |twitter_rest_client_instance|
results = twitter_rest_client_instance.retweeted_by_user(....)
...
end
这篇关于创建对象以调用 retweeted_by_user的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
更多推荐
[db:关键词]
发布评论