Module ActiveSupport::CoreExtensions::Hash::Keys
In: vendor/rails/activesupport/lib/active_support/core_ext/hash/keys.rb

Methods

Public Instance methods

[Source]

    # File vendor/rails/activesupport/lib/active_support/core_ext/hash/keys.rb, line 46
46:         def assert_valid_keys(valid_keys)
47:           unknown_keys = keys - valid_keys
48:           raise(ArgumentError, "Unknown key(s): #{unknown_keys.join(", ")}") unless unknown_keys.empty?
49:         end

Return a new hash with all keys converted to strings.

[Source]

    # File vendor/rails/activesupport/lib/active_support/core_ext/hash/keys.rb, line 6
 6:         def stringify_keys
 7:           inject({}) do |options, (key, value)|
 8:             options[key.to_s] = value
 9:             options
10:           end
11:         end

Destructively convert all keys to strings.

[Source]

    # File vendor/rails/activesupport/lib/active_support/core_ext/hash/keys.rb, line 14
14:         def stringify_keys!
15:           keys.each do |key|
16:             unless key.class.to_s == "String" # weird hack to make the tests run when string_ext_test.rb is also running
17:               self[key.to_s] = self[key]
18:               delete(key)
19:             end
20:           end
21:           self
22:         end

Return a new hash with all keys converted to symbols.

[Source]

    # File vendor/rails/activesupport/lib/active_support/core_ext/hash/keys.rb, line 25
25:         def symbolize_keys
26:           inject({}) do |options, (key, value)|
27:             options[key.to_sym] = value
28:             options
29:           end
30:         end

Destructively convert all keys to symbols.

[Source]

    # File vendor/rails/activesupport/lib/active_support/core_ext/hash/keys.rb, line 33
33:         def symbolize_keys!
34:           keys.each do |key|
35:             unless key.is_a?(Symbol)
36:               self[key.to_sym] = self[key]
37:               delete(key)
38:             end
39:           end
40:           self
41:         end
to_options()

Alias for symbolize_keys

to_options!()

Alias for symbolize_keys!

[Validate]