Method: Linked::List#shift

Defined in:
lib/linked/list.rb

#shiftListable?

Shift the first item off the list.

Returns:

  • (Listable, nil)

    the first item in the list, or nil if the list is empty.



114
115
116
117
118
119
120
121
122
123
124
# File 'lib/linked/list.rb', line 114

def shift
  return nil if empty?

  if list_head.last?
    @_chain.tap { @_chain = nil }
  else
    old_head = list_head
    @_chain = list_head.next
    old_head.delete
  end
end