Method: ArrayModel.attr_model_reader
- Defined in:
- lib/array_model.rb
.attr_model_reader(name, options = {}) ⇒ Object
Adds attr_reader methods to the class for a given field in the data hash. The :key: option can be used to set the name of the key in the hash, if it doesn’t have the same name as the method
class Users < ArrayModel
...
attr_model_reader :username
attr_model_reader :user_id, :key => :userId
...
end
111 112 113 114 115 |
# File 'lib/array_model.rb', line 111 def self.attr_model_reader(name, = {}) define_method name.to_sym do values[([:key] || name).to_sym] end end |