为什么下面的代码导致Foo :: People:Class'
错误'undefined local variable或method`foo_client'class Foo::People
class << self
def get_account_balance(account_num)
foo_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
答案 0 :(得分:7)
def get_account_balance
位于class << self
块内,因此它是一个类方法。 def foo_client
不是,所以它是一个实例方法。因此,您无法从foo_client
拨打get_account_balance
,因为您没有在People
的实例上调用它。