Ruby 中的 super 关键字 [英] Super keyword in Ruby

查看:46
本文介绍了Ruby 中的 super 关键字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这段代码中的 super 是什么?

What is the super for in this code?

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

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

As far as I know it's like calling the function recursively, right?

推荐答案

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

no... super calls the method of the parent class, if it exists. Also, as @EnabrenTane pointed out, it passes all the arguments to the parent class method as well.

这篇关于Ruby 中的 super 关键字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆