Class: Hash

Inherits:
Object
  • Object
show all
Defined in:
lib/casual_support/hash/setbang.rb

Instance Method Summary collapse

Instance Method Details

#set!(key, value) ⇒ Hash

Sets a value like Hash#[]=, but returns the modified Hash instead of the value. Useful with #reduce, and 2x faster than using an equivalent Hash#merge! (see benchmark).

Parameters:

  • key
  • value

Returns:

  • (Hash)

    the modified hash



11
12
13
14
# File 'lib/casual_support/hash/setbang.rb', line 11

def set!(key, value)
  self[key] = value
  self
end