Module: Raft::Goliath::HashMarshalling

Defined in:
lib/raft/goliath.rb

Class Method Summary collapse

Class Method Details

.hash_to_object(hash, klass) ⇒ Object



86
87
88
89
90
91
92
# File 'lib/raft/goliath.rb', line 86

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



94
95
96
97
98
# File 'lib/raft/goliath.rb', line 94

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