Ruby on rails 为什么ActiveSupport中的类\u可继承\u读取器没有文档化?

Ruby on rails 为什么ActiveSupport中的类\u可继承\u读取器没有文档化?,ruby-on-rails,ruby,activesupport,Ruby On Rails,Ruby,Activesupport,为了弄清楚Rails中类_可继承_读取器的文档位置,我费了好大劲 谷歌搜索揭示了它的存在,通过搜索gem本身,你可以找到以下方法: def class_inheritable_reader(*syms) syms.each do |sym| next if sym.is_a?(Hash) class_eval <<-EOS def self.#{sym} # def self.before_add_for_

为了弄清楚Rails中类_可继承_读取器的文档位置,我费了好大劲

谷歌搜索揭示了它的存在,通过搜索gem本身,你可以找到以下方法:

def class_inheritable_reader(*syms)
  syms.each do |sym|
    next if sym.is_a?(Hash)
    class_eval <<-EOS
      def self.#{sym}                        # def self.before_add_for_comments
        read_inheritable_attribute(:#{sym})  #         read_inheritable_attribute(:before_add_for_comments)
      end                                    # end
                                             #
      def #{sym}                             # def before_add_for_comments
        self.class.#{sym}                    #   self.class.before_add_for_comments
      end                                    # end
    EOS
  end
end
....
def类可继承读卡器(*syms)
syms.每个do | sym|
下一个if sym.is_a?(散列)

等级评估。它似乎是类的扩展。没有文档,但您可以看到实现。

。它似乎是类的扩展。没有文档,但您可以看到实现。

如果打开计算机上安装gems的文件夹,您可以导航到:

activesupport/lib/active\u support/core\u ext/class/inheritable\u attributes.rb

查看类的实际实现位置。此外,您可以在GitHub上的Rails存储库中看到

该文件(如下)中有类级文档,但没有方法级文档,这就是您可能找不到任何内容的原因

# Allows attributes to be shared within an inheritance hierarchy, but where each descendant gets a copy of
# their parents' attributes, instead of just a pointer to the same. This means that the child can add elements
# to, for example, an array without those additions being shared with either their parent, siblings, or
# children, which is unlike the regular class-level attributes that are shared across the entire hierarchy.

如果打开计算机上安装gems的文件夹,您可以导航到:

activesupport/lib/active\u support/core\u ext/class/inheritable\u attributes.rb

查看类的实际实现位置。此外,您可以在GitHub上的Rails存储库中看到

该文件(如下)中有类级文档,但没有方法级文档,这就是您可能找不到任何内容的原因

# Allows attributes to be shared within an inheritance hierarchy, but where each descendant gets a copy of
# their parents' attributes, instead of just a pointer to the same. This means that the child can add elements
# to, for example, an array without those additions being shared with either their parent, siblings, or
# children, which is unlike the regular class-level attributes that are shared across the entire hierarchy.

嗨,汤姆,今天……谢谢。不幸的是,这正是我搜索谷歌时登陆的网站。我希望有更多的官方文件。我会更新我的问题更详细一点,还有一个“额外”的问题,因为我已经找到了一个满意的答案。嗨,汤姆今天…谢谢。不幸的是,这正是我搜索谷歌时登陆的网站。我希望有更多的官方文件。我会更新我的问题更详细一点,还有一个“额外”的问题,因为我已经找到了一个满意的答案。