ruby - ruby 中未定义的局部变量或方法“action_name”错误
问题描述
我在基类中有两个方法,method_1 通过调用worker 执行带有一些*args 的perform_async,工作完成后它将调用method_2,如何将相同的args 传递给method_2?
def self.method_1(action_name, *args)
perform_async(action_name,args)
method_2
end
def self.method_2
some action here
method_1(action_name, args)
handle exception here
end
在方法 2 的第 3 行出现错误未定义的局部变量或方法“action_name”。
解决方案
如果我理解您的目的,那么使用实例变量来存储 splat 参数参数怎么样?
def self.method_1(action_name, *args)
@args = args
perform_async(action_name, args)
method_2
end
def self.method_2
some action here
method_1(action_name, @args)
handle exception here
end
推荐阅读
- bash - grep 包含来自 rsync 输出的错误结果
- html - 如何在 Angular 中比较 tagName 和字符串的值?
- python - 构建网络抓取循环以提取药物信息
- javascript - 使用 javascript 禁用与网站的连接
- amazon-web-services - Jenkins CLI 下载失败,出现 500 错误或 503 错误
- delphi - Firemonkey Android 9 方向传感器在 Delphi 10.3.3 中不起作用
- r - 识别与泛型函数关联的方法
- selenium - 如何修复机器人框架和 seleniumlibrary 中的“不存在的设置”错误?
- mysql - Windows ODBC 驱动程序 - 检索到的表情符号数据呈现为?
- python - 使用略有不同的前缀更改许多文件名