Created
December 10, 2010 16:24
-
-
Save adeolaawoyemi/736417 to your computer and use it in GitHub Desktop.
the ruby way
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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