Class: Integer
- Inherits:
-
Object
- Object
- Integer
- Defined in:
- lib/qat/core_ext/integer.rb
Overview
Integer Class extension
Class Method Summary collapse
-
.random(length = 1) ⇒ Integer
Generates a random integer with a given number of digits.
Class Method Details
.random(length = 1) ⇒ Integer
Generates a random integer with a given number of digits
7 8 9 10 11 |
# File 'lib/qat/core_ext/integer.rb', line 7 def self.random(length=1) raise(ArgumentError, 'Argument should be an Integer!') unless length.is_a?(Integer) elements = (0..9).to_a [(1..9).to_a.sample, (length-1).times.map { elements.sample }].flatten.join.to_i end |