to_options

to_options() Instance Public methods Alias for: symbolize_keys

symbolize_keys!

symbolize_keys!() Instance Public methods Destructively convert all keys to symbols, as long as they respond to to_sym. Same as symbolize_keys, but modifies self. to_options!

symbolize_keys

symbolize_keys() Instance Public methods Returns a new hash with all keys converted to symbols, as long as they respond to to_sym. hash = { 'name' => 'Rob', 'age' => '28' } hash.symbolize_keys # => { name: "Rob", age: "28" } to_options

stringify_keys!

stringify_keys!() Instance Public methods Destructively convert all keys to strings. Same as stringify_keys, but modifies self.

stringify_keys

stringify_keys() Instance Public methods Returns a new hash with all keys converted to strings. hash = { name: 'Rob', age: '28' } hash.stringify_keys # => { "name" => "Rob", "age" => "28" }

slice!

slice!(*keys) Instance Public methods Replaces the hash with only the given keys. Returns a hash containing the removed key/value pairs. { a: 1, b: 2, c: 3, d: 4 }.slice!(:a, :b) # => {:c=>3, :d=>4}

slice

slice(*keys) Instance Public methods Slice a hash to include only the given keys. This is useful for limiting an options hash to valid keys before passing to a method: def search(criteria = {}) criteria.assert_valid_keys(:mass, :velocity, :time) end search(options.slice(:mass, :velocity, :time)) If you have an array of keys you want to limit to, you should splat them: valid_keys = [:mass, :velocity, :time] search(options.slice(*valid_keys))

reverse_update

reverse_update(other_hash) Instance Public methods Alias for: reverse_merge!

reverse_merge!

reverse_merge!(other_hash) Instance Public methods Destructive reverse_merge. reverse_update

reverse_merge

reverse_merge(other_hash) Instance Public methods Merges the caller into other_hash. For example, options = options.reverse_merge(size: 25, velocity: 10) is equivalent to options = { size: 25, velocity: 10 }.merge(options) This is particularly useful for initializing an options hash with default values.