#!/usr/bin/env ruby # # Selection Sort # "Learn to Program" by Chris Pine, p. 81 # def sort some_array # This "wraps" recursive_sort. recursive_sort some_array, [] end def recursive_sort unsorted_array, sorted_array return sorted_array if unsorted_array == [] smallest = unsorted_array.first unsorted_array.each do |item| smallest = item if item < smallest end unsorted_array.delete(smallest) sorted_array.push(smallest) recursive_sort(unsorted_array, sorted_array) end def input print '> ' return gets.chomp end a = [] s = input while s.downcase != 'quit' a.push(s) s = input end puts sort(a)