Ruby on rails “超级”be模块是什么?

Ruby on rails “超级”be模块是什么?,ruby-on-rails,Ruby On Rails,我正在尝试从rails读取一些代码。有些我不明白。希望得到一些帮助 来自active\u support/dependencies/autoload.rb的代码。方法是自动加载 def autoload(const_name, path = @_at_path) unless path full = [name, @_under_path, const_name.to_s].compact.join("::") path = Inflector.underscore(ful

我正在尝试从rails读取一些代码。有些我不明白。希望得到一些帮助

来自
active\u support/dependencies/autoload.rb
的代码。方法是
自动加载

 def autoload(const_name, path = @_at_path)
  unless path
    full = [name, @_under_path, const_name.to_s].compact.join("::")
    path = Inflector.underscore(full)
  end

  if @_eager_autoload
    @_autoloads[const_name] = path
  end

  super const_name, path
end
  • 我的问题是这里的
    super
    将是什么
  • 是否有一份文件或书籍说明了来源

super
是一个ruby方法,它从继承的类中调用相同的命名方法,在本例中为
自动加载。我不知道我是否说得很清楚,因为英语不是我的母语,所以我将通过示例向您展示:

class Human
  def shout(words)
    puts "I am yelling #{words}"
  end
end

class Person < Human
  def shout(words)
    puts "I am #{words}"
    puts super "loud"
  end
 end

Person.new.shout("awesome")

Output:
I am awesome
I am yelling loud
类人类
(字)
放上“我在喊{words}”
终止
终止
类人<人
(字)
放上“我是{words}”
超级“响亮”
终止
终止
Person.new.shout(“太棒了”)
输出:
我太棒了
我在大声喊叫

所讨论的方法被定义为模块
ActiveSupport::Autoload
拥有的实例方法。由于这是一个模块,为了使实例方法始终处于活动状态,该模块必须包含在某个类中。什么是
super
取决于这个类是什么。将查找相关类的所有祖先,以便使用
#autoload
方法。如果没有人定义它,
Kernel#autoload
将被命中,这总是存在的。

很难说询问者是否不知道super
做了什么,或者ze不知道在这种特殊情况下超类将是什么。顺便说一句,我知道super方法。我只是想知道在这种情况下,super是什么。谢谢。我忘记了
kernel#autoload
方法。