Module: Spark::CoreExtension::Hash::InstanceMethods

Defined in:
lib/spark/ext/hash.rb

Instance Method Summary collapse

Instance Method Details

#stringify_keys_with_spark!Object

Destructively convert all keys to strings.



9
10
11
# File 'lib/spark/ext/hash.rb', line 9

def stringify_keys_with_spark!
  transform_keys!{ |key| key.to_s }
end

#symbolize_keys_with_spark!Object

Destructively convert all keys to symbols, as long as they respond



14
15
16
# File 'lib/spark/ext/hash.rb', line 14

def symbolize_keys_with_spark!
  transform_keys!{ |key| key.to_sym rescue key }
end

#transform_keys_with_spark!Object

Destructively convert all keys using the block operations. Same as transform_keys but modifies self.



20
21
22
23
24
25
# File 'lib/spark/ext/hash.rb', line 20

def transform_keys_with_spark!
  keys.each do |key|
    self[yield(key)] = delete(key)
  end
  self
end