I'm new to ruby and I have the following code:

  index=0
  unsorted_array.each do |value|
    if index==0
      smallest=value
      smallest_index=0
    elsif value<smallest
      smallest=value
      smallest_index=index
    end
    index=index+1
  end

When it gets to index 1, it crashes and says that smallest is
undefined (on the elsif line).  Why is that, when it gets defined in
the first pass (index = 0) ?

Thanks for helping a newbie out.

Tim