Top Level Namespace
Instance Method Summary collapse
-
#rand_let(options = {}) ⇒ Object
Returns a random upper or lowercase letter.
-
#rand_phone(options = {}) ⇒ Object
Returns a random phone number w/ an area code of 210 (no international prefixes).
-
#rand_token(length = 36) ⇒ Object
Gets a random length (default 36) character string consisting of uppercase and lowercase letters and numbers 0-9.
-
#random(min, max, options = {}) ⇒ Object
Returns a number >= min, but <= max.
Instance Method Details
#rand_let(options = {}) ⇒ Object
Returns a random upper or lowercase letter
7 8 9 10 11 12 |
# File 'lib/random-utils.rb', line 7 def rand_let ={} uppercase = random(0, 2) == 1 uppercaseLet = random(65, 91).chr letter = (uppercase) ? (uppercaseLet) : (uppercaseLet.downcase) letter end |
#rand_phone(options = {}) ⇒ Object
Returns a random phone number w/ an area code of 210 (no international prefixes)
15 16 17 |
# File 'lib/random-utils.rb', line 15 def rand_phone ={} "210#{random(1111111, 9999999).to_s}" end |
#rand_token(length = 36) ⇒ Object
Gets a random length (default 36) character string consisting of uppercase and lowercase letters and numbers 0-9
21 22 23 24 25 26 27 |
# File 'lib/random-utils.rb', line 21 def rand_token length=36 token = '' length.times do token += (random(0, 2)==1) ? (random(0,10).to_s) : (rand_let()) end token end |
#random(min, max, options = {}) ⇒ Object
Returns a number >= min, but <= max
2 3 4 |
# File 'lib/random-utils.rb', line 2 def random min, max, ={} rand(max - min) + min end |