Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails ruby中的API包装器不带参数?_Ruby On Rails_Ruby_Rest_Httparty - Fatal编程技术网

Ruby on rails ruby中的API包装器不带参数?

Ruby on rails ruby中的API包装器不带参数?,ruby-on-rails,ruby,rest,httparty,Ruby On Rails,Ruby,Rest,Httparty,我正在编写一个库来和我当前的包装器进行交互,以获取当前游戏信息如下所示 require "httparty" class Elophant include HTTParty base_uri 'api.elophant.com' def initialize(name, region) @options = {query: { summoner_name: name, region: region,

我正在编写一个库来和我当前的包装器进行交互,以获取
当前游戏信息
如下所示

require "httparty"

class Elophant
    include HTTParty
    base_uri 'api.elophant.com'

    def initialize(name, region)
        @options = {query: {
            summoner_name: name,
            region: region,
            key: ENV["ELOPHANT_API_KEY"]
        }}
    end

    def self.current_game
        HTTParty.get("/v2/#{region}/in_progress_game_info/#{summoner_name}?key=#{key}", @options)
    end

    def self.summoner_info
        HTTParty.get("/v2/#{region}/summoner/#{summoner_name}?key=#{key}", @options)
    end
end
所以我可以打电话

elophant = Elophant.new
elophant.current_game("summoner_name", "OCE")
像这样将此信息发送到我的rails视图

  def index
    elophant = Elophant.new
    @CurrentGame = elophant.current_game("summoner_name", "OCE")
  end
但是rails抛出了这个错误

wrong number of arguments (0 for 2)

    base_uri 'api.elophant.com'

    def initialize(name, region)
        @options = {query: {
            summoner_name: name,
            region: region,

试着像这样使用
Elpohant
类:

elophant = Elophant.new("summoner_name", "OCE")
elophant.current_game
您已将
Elophant
定义为在初始值设定项中有两个参数,即
caller\u name
region
。但是,您在调用
当前\u游戏时传递了这些


如果在您的情况下,这些参数是方法调用的本地参数,并且可以根据调用的方法而更改,那么您可能希望将这些参数带到方法中,即在本例中,
current_game

您已经用两个参数定义了Elophant的初始值设定项。因此,当你调用Elophant.new时,你应该提供名称和区域值。我认为
@options
允许我使用我使用的语法?好的,我已经这样做了,现在它抛出了一个错误,说它找不到变量
区域
,尽管我传递了@options,并且在尝试
查询时,它说它找不到查找
current\u game
methodOk错过了那一位-
current\u game
caller\u info
都是类方法,有没有理由让它们不是实例方法?很好,尽管尝试
def caller\u info
会返回相同的错误