Class: Hash

Inherits:
Object show all
Defined in:
lib/mongo_record/core_ext.rb

Instance Method Summary collapse

Instance Method Details

#symbolize_keysObject

Same symbolize_keys method used in Rails



54
55
56
57
58
59
# File 'lib/mongo_record/core_ext.rb', line 54

def symbolize_keys
  inject({}) do |options, (key, value)|
    options[(key.to_sym rescue key) || key] = value
    options
  end
end

#symbolize_keys!Object



61
62
63
# File 'lib/mongo_record/core_ext.rb', line 61

def symbolize_keys!
  self.replace(self.symbolize_keys)
end

#to_mongo_valueObject

Convert an Hash to a Mongo value. Used by MongoRecord::Base when saving data to Mongo.



47
48
49
50
51
# File 'lib/mongo_record/core_ext.rb', line 47

def to_mongo_value
  h = {}
  self.each {|k,v| h[k] = v.to_mongo_value}
  h
end