Module: Norma43::Models::Mixins::AttributesAssignment
- Included in:
- Account, AdditionalCurrency, AdditionalItem, Document, Transaction
- Defined in:
- lib/norma43/models/mixins/attributes_assignment.rb
Constant Summary collapse
- EMPTY_ATTRIBUTES =
{}.freeze
Instance Method Summary collapse
- #attributes ⇒ Object (also: #to_hash, #to_h)
- #attributes=(new_attributes) ⇒ Object
Instance Method Details
#attributes ⇒ Object Also known as: to_hash, to_h
18 19 20 21 22 23 24 25 26 27 |
# File 'lib/norma43/models/mixins/attributes_assignment.rb', line 18 def attributes instance_variables.map { |ivar_name| attr_reader_method_name = ivar_name.to_s.delete_prefix("@").to_sym next unless public_methods(false).include?(attr_reader_method_name) attr_value = public_send(attr_reader_method_name) [attr_reader_method_name, attr_value] }.compact.to_h end |
#attributes=(new_attributes) ⇒ Object
9 10 11 12 13 14 15 16 |
# File 'lib/norma43/models/mixins/attributes_assignment.rb', line 9 def attributes=(new_attributes) Hash(new_attributes).each do |attr_name, attr_value| attr_writer_method_name = "#{attr_name}=".to_sym next unless public_methods(false).include?(attr_writer_method_name) public_send(attr_writer_method_name, attr_value) end end |