当我将一个引用拉入包的方法放在另一个方法中时,它会离开范围并失败。
这样做的正确方法是什么。我尝试过玩“自我”,但我是新手,但没有成功。
所需的解决方案。不工作。返回错误。
nil:NilClass (NoMethodError) 的未定义方法“accounts”
require 'package that has 'accounts''
class Name
@sandbox = #working API connection
def get_account
@sandbox.accounts do |resp| #This is where error is
resp.each do |account|
if account.name == "John"
name = account.name
end
end
end
end
end
new = Name.new
p new.get_account
这可行,但不会创建可重用的方法。
require 'package that has 'accounts''
class Name
@sandbox = #working API connection
@sandbox.accounts do |resp|
resp.each do |account|
if account.name == "John"
p account.name
end
end
end
end
new = Name.new