gpt4 book ai didi

ruby - super 的论据

转载 作者:数据小太阳 更新时间:2023-10-29 08:50:27 25 4
gpt4 key购买 nike

我有一个调用基础实现的方法:

class B
def m x, y
x + y
end
end

class C < B
def m x, y
super * 10
end
end

因为我从不在我的派生方法中引用参数,有没有办法避免在 C.m 中使用参数名称?

最佳答案

认为这是您最接近的:

class B
def m x, y
x + y
end
end

class C < B
def m *args
super * 10
end
end

=> C.new.m 10, 10 # 200
=> C.new.m 1, 2, 3 # ArgumentError

关于ruby - super 的论据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14327285/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com