-
-
Save altamic/257421 to your computer and use it in GitHub Desktop.
randpath
This file contains 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
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