Skip to content

Instantly share code, notes, and snippets.

@closer
Created August 26, 2009 01:30
Show Gist options
  • Save closer/175230 to your computer and use it in GitHub Desktop.
Save closer/175230 to your computer and use it in GitHub Desktop.
random select in ruby
module Kernel
def random arg
arg = arg.to_a if arg.class == Range
arg[rand(arg.size)]
end
end
class Range
def random
Kernel.random self
end
end
class Array
def random
Kernel.random self
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment