RosettaCodeData/Task/Search-a-list/Ruby/search-a-list-1.rb

10 lines
224 B
Ruby
Raw Permalink Normal View History

2023-07-01 11:58:00 -04:00
haystack = %w(Zig Zag Wally Ronald Bush Krusty Charlie Bush Bozo)
%w(Bush Washington).each do |needle|
if (i = haystack.index(needle))
puts "#{i} #{needle}"
else
raise "#{needle} is not in haystack\n"
end
end