Skip to content

Instantly share code, notes, and snippets.

@adeolaawoyemi
Created December 10, 2010 16:24
Show Gist options
  • Save adeolaawoyemi/736417 to your computer and use it in GitHub Desktop.
Save adeolaawoyemi/736417 to your computer and use it in GitHub Desktop.
the ruby way
# Choose random window, the Ruby way ;-)
windows_array = ['one', 'two', 'three', 'four']
windows_hash = Hash[ *windows_array.collect { |v| [ v, v ] }.flatten ]
def get_random_window(wa,wh)
windows_count = wa.length
puts "We have #{windows_count} windows"
chosen = rand(windows_count);
name = wa[chosen]
title = wh[name]
puts "We have chosen window #{chosen+1}"
puts "NAME: #{name}"
puts "TITLE: #{title}"
end
get_random_window(windows_array, windows_hash)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment