Class: VirtusConvert::Hash
- Inherits:
-
Object
- Object
- VirtusConvert::Hash
- Defined in:
- lib/virtus_convert/hash.rb
Instance Method Summary collapse
-
#initialize(hash = {}) ⇒ Hash
constructor
A new instance of Hash.
- #to_hash ⇒ Object
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_hash ⇒ Object
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 |