Skip to content

End of Life Ruby 3.1 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →

instance method

Kernel#Hash

Hash(arg) → hash

Converts arg to a Hash by calling arg.to_hash. Returns an empty Hash when arg is nil or [].

Example
Hash([])          #=> {}
Hash(nil)         #=> {}
Hash(key: :value) #=> {:key => :value}
Hash([1, 2, 3])   #=> TypeError
See also #gsub #Integer #global_variables #iterator? also in 4.1 · 4.0 · 3.4 · 3.3 · 3.2 · 3.0