Class: VirtusConvert::Hash

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

Instance Method Summary collapse

Constructor Details

#initialize(hash = {}, options = {}) ⇒ Hash

Returns a new instance of Hash.



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

def initialize(hash = {}, options = {})
  hash.reject!{|k, v| v.nil?} if options[:reject_nils]
  @hash = hash.inject({}){|h,(k,v)| h[k] = VirtusConvert.new(v, options); h}
end

Instance Method Details

#to_hashObject



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

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