gpt4 book ai didi

ruby - Ruby 中的 super 关键字

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

这段代码中的 super 是做什么用的?

def initialize options = {}, &block
@filter = options.delete(:filter) || 1
super
end

据我所知,这就像递归调用函数,对吧?

最佳答案

no...super调用父类的方法,如果存在的话。此外,正如@EnabrenTane 指出的那样,它还将所有参数传递给父类方法。

关于ruby - Ruby 中的 super 关键字,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4632224/

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