Class: Hash
- Inherits:
-
Object
- Object
- Hash
- Defined in:
- lib/mongo_odm/core_ext/conversions.rb,
lib/mongo_odm/core_ext/hash_recursive_merge.rb
Class Method Summary (collapse)
Instance Method Summary (collapse)
- - (Object) dereference
- - (Object) rmerge(other_hash)
- - (Object) rmerge!(other_hash)
- - (Object) to_mongo
Class Method Details
+ (Object) type_cast(value)
244 245 246 247 |
# File 'lib/mongo_odm/core_ext/conversions.rb', line 244 def self.type_cast(value) return nil if value.nil? Hash[value.to_hash.map{|k,v| [MongoODM.instanciate(k), MongoODM.instanciate(v)]}] end |
Instance Method Details
- (Object) dereference
253 254 255 |
# File 'lib/mongo_odm/core_ext/conversions.rb', line 253 def dereference Hash[self.map{|k,v| [MongoODM.instanciate(MongoODM.dereference(k)), MongoODM.instanciate(MongoODM.dereference(v))]}] end |
- (Object) rmerge(other_hash)
8 9 10 11 12 13 |
# File 'lib/mongo_odm/core_ext/hash_recursive_merge.rb', line 8 def rmerge(other_hash) result = {} merge(other_hash) do |key, old_value, new_value| result[key] = old_value.class == self.class ? old_value.rmerge(new_value) : new_value end end |
- (Object) rmerge!(other_hash)
2 3 4 5 6 |
# File 'lib/mongo_odm/core_ext/hash_recursive_merge.rb', line 2 def rmerge!(other_hash) merge!(other_hash) do |key, old_value, new_value| old_value.class == self.class ? old_value.rmerge!(new_value) : new_value end end |
- (Object) to_mongo
249 250 251 |
# File 'lib/mongo_odm/core_ext/conversions.rb', line 249 def to_mongo Hash[self.map{|k,v| [k.to_mongo, v.to_mongo]}] end |