Module: Bank::Model
- Defined in:
- lib/bank/model.rb
Defined Under Namespace
Classes: Config
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object
- #get(attr) ⇒ Object
- #initialize(attrs = {}) ⇒ Object
- #set(attr, value = nil) ⇒ Object
- #to_hash ⇒ Object
Class Method Details
Instance Method Details
#==(other) ⇒ Object
55 56 57 |
# File 'lib/bank/model.rb', line 55 def ==(other) other.is_a?(self.class) && other.to_hash == to_hash end |
#get(attr) ⇒ Object
41 42 43 |
# File 'lib/bank/model.rb', line 41 def get(attr) instance_variable_get(:"@#{attr}") end |
#initialize(attrs = {}) ⇒ Object
30 31 32 33 |
# File 'lib/bank/model.rb', line 30 def initialize(attrs = {}) set(attrs) _defaults.reject { |key, _| get(key) }.each { |key, val| set(key, val) } end |
#set(attr, value = nil) ⇒ Object
45 46 47 48 49 50 51 52 53 |
# File 'lib/bank/model.rb', line 45 def set(attr, value = nil) if attr.is_a?(Hash) attr.each { |key, value| set(key, value) } else public_send(:"#{attr}=", value) end return self end |
#to_hash ⇒ Object
35 36 37 38 39 |
# File 'lib/bank/model.rb', line 35 def to_hash _fields.reduce({}) do |acc, field| acc.merge(field => get(field)) end end |