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

10 lines
224 B
Ruby
Raw Permalink Normal View History

2013-04-10 12:38:42 -07:00
haystack = %w(Zig Zag Wally Ronald Bush Krusty Charlie Bush Bozo)
%w(Bush Washington).each do |needle|
if (i = haystack.index(needle))
2015-11-18 06:14:39 +00:00
puts "#{i} #{needle}"
2013-04-10 12:38:42 -07:00
else
raise "#{needle} is not in haystack\n"
end
end