我正在使用Ruby on Rails 3.2.9和Ruby 1.9.3。我试图实现一种方法,在该方法中运行send
方法,并且我想传递给传递给下级方法的参数的“发送”方法全部参数。也就是说,给定如何传递参数传递给另一个方法?
def method1(arg1, arg2 = true, *args)
# ...
self.class.send(:method2, # passing all arguments passed to method1, whatever those are)
end
话,我想通过所有参数传递给method1
(在这种情况下,arg1, arg2 = true, *args
)的method2
。
如何应该我做到了吗?例如,是否有可能在send
上使用Ruby“splat”功能?
的可能的复制[红宝石:我如何通过一个方法收到另一个所有参数和块?](HTTP:/ /stackoverflow.com/questions/4683844/ruby-how-do-i-pass-all-parameters-and-blocks-recieved-by-one-method-to-another) –