views:

115

answers:

2

Hi there, Pulling my hair out trying to figure out where class_inheritable_reader is documented in Rails.

A Google search revealed its existence, and looking in the gem itself ya find the method:

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
....

But looking at the rdocs for both ActiveSupport AND from 'rake doc:rails' you'll find no documentation...how come?

A: 

I found it on APIdock. It appears to be an extension to Class. No documentation but you can see the implementation.

Thomas Brice
Hi TomToday...thanks. Unfortunately that's exactly the site I landed in when I searched Google. I was hoping for more official documentation. I'll update my question with a little more detail, and a 'bonus' question since I've found a satisfactory answer for the time being.
btelles
A: 

If you open up the folder where gems are installed on your machine, you can navigate to:

activesupport/lib/active_support/core_ext/class/inheritable_attributes.rb

to see where the class is actually implemented. In addition, you can see the latest version of the file in the Rails repository on GitHub.

There is class level documentation available in that file (below), but no method level documentation, which is why you probably couldn't find anything.

# 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.
Martin Gordon