Skip to content

Instantly share code, notes, and snippets.

@daniel-g
Created January 27, 2011 17:31
Show Gist options
  • Save daniel-g/798853 to your computer and use it in GitHub Desktop.
Save daniel-g/798853 to your computer and use it in GitHub Desktop.
Random Enumerable
class Random
include Enumerable
def initialize(limit)
@limit = limit
end
def each(counter = 10)
i = 0
while i < counter
yield rand(@limit)
i += 1
end
end
end
r = Random.new(100)
r.each{|ran| puts ran}
puts "-----"
puts r.max
puts r.min
puts "-----"
puts r.sort
puts r.sort_by{|element| element%10}
puts "------"
puts r.inject(:+)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment