我有一个带有子类的基类,它覆盖了一个带有多个参数的方法。
class Parent
def foo *bar
end
end
class Child < Parent
def foo bar, baz
end
end
这很好用。但是,假设在Parent中有一个方法foobar调用foo:
def foobar *foo_args
foo foo_args
end
在Child实例上调用时会引发ArgumentError,因为foo_args是一个单独的数组,而Child.new.foo需要两个对象。有办法解决这个问题吗?
答案 0 :(得分:1)
您的问题不明确,但我认为这可能是您想要的:
def foobar *foo_args
foo(*foo_args)
end
仍然,Child.new.foo
必须使用两个参数才能引发错误。