拉出我的头发试图弄清楚Rails中记录了class_inheritable_reader的位置。
谷歌搜索显示它的存在,并查看宝石本身你找到方法:
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
....
但是看看ActiveSupport的rdocs和'rake doc:rails'你会发现没有文档......为什么会这样?
答案 0 :(得分:1)
如果您打开计算机上安装了gem的文件夹,则可以导航到:
的ActiveSupport / LIB / active_support / core_ext /类/ inheritable_attributes.rb
查看实际实现类的位置。此外,您可以在GitHub上的Rails存储库中看到latest version of the file。
该文件中提供了类级文档(如下所示),但没有方法级文档,这就是您可能找不到任何内容的原因。
# 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.
答案 1 :(得分:0)
I found it on APIdock。它似乎是Class的扩展。没有文档,但您可以看到实现。