Class: Array

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby_extensions.rb

Overview

Various monkeypatching

Instance Method Summary collapse

Instance Method Details

#to_hObject

Turns an array of the form [[key, value], …] into a hash of the form {key => value }

[[:a, 1], [:b, 2]].to_h    #=> {a => 1, :b => 2}


6
7
8
# File 'lib/ruby_extensions.rb', line 6

def to_h
  inject({}) { |m, e| m[e[0]] = e[1]; m }
end