Class: VirtusConvert::Hash

Inherits:
Object
  • Object
show all
Defined in:
lib/virtus_convert/hash.rb

Instance Method Summary collapse

Constructor Details

#initialize(hash = {}) ⇒ Hash

Returns a new instance of Hash.



3
4
5
# File 'lib/virtus_convert/hash.rb', line 3

def initialize(hash = {})
  @hash = hash.inject({}){|h,(k,v)| h[k] = VirtusConvert.new(v); h}
end

Instance Method Details

#to_hashObject



7
8
9
10
11
12
# File 'lib/virtus_convert/hash.rb', line 7

def to_hash
  @hash.inject({}) do |hash,(k, v)|
    hash[k] = (v.respond_to?(:to_hash) ? v.to_hash : v)
    hash
  end
end