Skip to content
instance method

Hash#store

(K arg0, V arg1) -> V
store(p1, p2)

Alias of #[]=

Associates the given object with the given key; returns object.

Searches for a hash key equivalent to the given key; see Hash Key Equivalence.

If the key is found, replaces its value with the given object; the ordering is not affected (see Entry Order):

Example
h = {foo: 0, bar: 1}
h[:foo] = 2 # => 2
h[:foo]     # => 2

If key is not found, creates a new entry for the given key and object; the new entry is last in the order (see Entry Order):

Example
h = {foo: 0, bar: 1}
h[:baz] = 2 # => 2
h[:baz]     # => 2
h           # => {:foo=>0, :bar=>1, :baz=>2}

Related: []; see also Methods for Assigning.

See also #[]= #slice #to_a #size also in 4.1 · 3.4 · 3.3 · 3.2 · 3.1 · 3.0