开发者

Creating a class method with Ruby problems

Why does the following code result in the error 'undefined local variable or method `foo_client' for Foo::People:Class'

class Foo::People

  class << self
    def get_account_balance(account_num)
      fo开发者_StackOverflow中文版o_client.request :get_account_balance, :body => {"AccountNum" => account_num}
    end
  end

  def foo_client
    @@client ||= Savon::Client.new do|wsdl, http|
      wsdl.document = PEOPLE_SERVICE_ENDPOINT[:uri] + "?WSDL"
      wsdl.endpoint = PEOPLE_SERVICE_ENDPOINT[:uri]
    end
  end

end


def get_account_balance is inside the class << self block, so it's a class method. def foo_client is not, so it's an instance method. So you can't call foo_client from get_account_balance because you're not calling it on an instance of People.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜