Method: Forecasting::Models::Base.attributed
- Defined in:
- lib/forecasting/models/base.rb
.attributed(*attribute_names) ⇒ Object
Class method to define attribute methods for accessing attributes for a record
It needs to be used like this:
class User < ForecastRecord
attributed :id,
:title,
:first_name
...
end
36 37 38 39 40 41 42 43 44 45 |
# File 'lib/forecasting/models/base.rb', line 36 def self.attributed(*attribute_names) attribute_names.each do |attribute_name| define_method(attribute_name) do @attributes[__method__.to_s] end define_method("#{attribute_name}=") do |value| @attributes[__method__.to_s.chop] = value end end end |