Module: Raft::Goliath::HashMarshalling

Defined in:
lib/raft/goliath.rb

Class Method Summary collapse

Class Method Details

.hash_to_object(hash, klass) ⇒ Object



89
90
91
92
93
94
95
# File 'lib/raft/goliath.rb', line 89

def self.hash_to_object(hash, klass)
  object = klass.new
  hash.each_pair do |k, v|
    object.send("#{k}=", v)
  end
  object
end

.object_to_hash(object, attrs) ⇒ Object



97
98
99
100
101
# File 'lib/raft/goliath.rb', line 97

def self.object_to_hash(object, attrs)
  attrs.reduce({}) { |hash, attr|
    hash[attr] = object.send(attr); hash
  }
end