Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between attributes and base_attributes in Ruby?

I've seen several models define a static method

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

and some other models define the static method

self.attributes
  @@attributes = {}
end

What exactly is the difference between attributes and base attributes?

like image 938
Kitty1911 Avatar asked Dec 16 '13 19:12

Kitty1911


1 Answers

Well in your example without knowing more about the code, the self.attributes method is using a class variable (@@attributes), which means that you could add more attributes to it at run time.

Where as your base_attributes is hard coded. I suspect you're seeing something like:

base_attributes.merge(attributes) which is a way of defining default values perhaps.

like image 185
MatthewFord Avatar answered Nov 03 '22 00:11

MatthewFord