Class: Hash

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

Instance Method Summary collapse

Instance Method Details

#assert_has_keys(*valid_keys) ⇒ Object

Raises:

  • (ArgumentError)


26
27
28
29
# File 'lib/ext/core_ext.rb', line 26

def assert_has_keys(*valid_keys)
  missing_keys = [valid_keys].flatten - keys
  raise(ArgumentError, "Missing Option(s): #{missing_keys.join(", ")}") unless missing_keys.empty?
end

#symbolize_keysObject



15
16
17
18
19
20
# File 'lib/ext/core_ext.rb', line 15

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

#symbolize_keys!Object



22
23
24
# File 'lib/ext/core_ext.rb', line 22

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