Skip to content
instance method

Hash#slice

(*K) -> ::Hash[K, V]
slice(*keys) → new_hash

Returns a new hash containing the entries from self for the given keys; ignores any keys that are not found:

Example
h = {foo: 0, bar: 1, baz: 2}
h.slice(:baz, :foo, :nosuch) # => {baz: 2, foo: 0}

Related: see Methods for Deleting.

See also #size #store #shift #to_a also in 4.1 · 3.4 · 3.3 · 3.2 · 3.1 · 3.0