Class: Array

Inherits:
Object
  • Object
show all
Defined in:
lib/instant_api/util/array.rb

Instance Method Summary collapse

Instance Method Details

#array_to_hashObject

a

-> a

a, b, c

-> { a => { b => c } }



5
6
7
8
9
10
11
12
13
14
# File 'lib/instant_api/util/array.rb', line 5

def array_to_hash
  head, *tail = *self
  if tail.empty?
    head
  elsif tail.size == 1
    {head => tail.first}
  else
    {head => tail.array_to_hash}
  end
end