Skip to content

Instantly share code, notes, and snippets.

@altamic
Forked from anonymous/gist:257152
Created December 15, 2009 23:54
Show Gist options
  • Save altamic/257421 to your computer and use it in GitHub Desktop.
Save altamic/257421 to your computer and use it in GitHub Desktop.
randpath
def rand_path(args)
path_index = (rand()*args.size).to_i
case args[path_index]
when Array then rand_path(args[path_index])
when Proc then args[path_index].call
else
puts "Discarded #{args[path_index].class} argument"
end
end
rand_path [[ lambda{ puts "1a"}, lambda{ puts "1b"} ], lambda{ puts "2"}, lambda{puts "3"}]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment