Difference between attributes and base_attributes in Ruby?

I saw several models define a static method

self.base_attributes { :object => [] } end 

and some other models define a static method

 self.attributes @@attributes = {} end 

What is the difference between attributes and basic attributes?

+6
source share
1 answer

In your example, without knowing more about the code, the self.attributes method uses a class variable ( @@attributes ), which means that you can add additional attributes to it at run time.

If your base_attributes hardcoded. I suspect you are seeing something like:

base_attributes.merge(attributes) , which can specify default values.

+1
source

All Articles