Method: Array#head

Defined in:
lib/ruby/jruby_hack.rb

#headObject

Return the first item. Raises an IndexError if the Array is empty?.

Examples:

[1, 2, 3].head  #=> 1

Raises:

  • (IndexError)


18
19
20
21
22
# File 'lib/ruby/jruby_hack.rb', line 18

def head
  raise IndexError, "head of empty list" if empty?
  x, = self
  x
end