[英]Error undefined local variable or method `action_name' in ruby
i have two methods in base class, method_1 does perform_async with some *args by calling the worker and after job is done it will call method_2, how to pass same args to method_2?我在基础 class 中有两种方法,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
getting error undefined local variable or method `action_name' in line number 3 of method 2.在方法 2 的第 3 行出现错误未定义的局部变量或方法“action_name”。
If I'm understanding what you're going for, what about using an instance variable to store the splat parameter arguments?如果我了解您要做什么,那么使用实例变量来存储 splat 参数 arguments 怎么样?
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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.