Module: RujitsuFixnum
- Defined in:
- lib/rujitsu/fixnum.rb
Instance Method Summary collapse
-
#random_characters(opts = {}) ⇒ Object
(also: #random_character)
produce a string of N random characters 5.random_characters.
-
#random_consonants(opts = {}) ⇒ Object
(also: #random_consonant)
produce a string of N random consonants.
- #random_hex_characters(opts = {}) ⇒ Object (also: #random_hex_character)
-
#random_letters(opts = {}) ⇒ Object
(also: #random_letter)
produce a string of N random letters 5.random_letters.
-
#random_numbers(opts = {}) ⇒ Object
(also: #random_number)
produce a string of N random numbers 5.random_numbers optionally specific limits on the numbers 5.random_numbers(:from => 1, :to => 5).
-
#random_vowels(opts = {}) ⇒ Object
(also: #random_vowel)
produce a string of N random vowels.
Instance Method Details
#random_characters(opts = {}) ⇒ Object Also known as: random_character
produce a string of N random characters
5.random_characters
47 48 49 |
# File 'lib/rujitsu/fixnum.rb', line 47 def random_characters opts={} generate_random_string_using CHARACTERS, opts end |
#random_consonants(opts = {}) ⇒ Object Also known as: random_consonant
produce a string of N random consonants
11 12 13 |
# File 'lib/rujitsu/fixnum.rb', line 11 def random_consonants opts={} generate_random_string_using CONSONANTS, opts end |
#random_hex_characters(opts = {}) ⇒ Object Also known as: random_hex_character
52 53 54 |
# File 'lib/rujitsu/fixnum.rb', line 52 def random_hex_characters opts={} generate_random_string_using HEX_CHARACTERS, opts end |
#random_letters(opts = {}) ⇒ Object Also known as: random_letter
produce a string of N random letters
5.random_letters
18 19 20 |
# File 'lib/rujitsu/fixnum.rb', line 18 def random_letters opts={} generate_random_string_using LETTERS, opts end |
#random_numbers(opts = {}) ⇒ Object Also known as: random_number
produce a string of N random numbers
5.random_numbers
optionally specific limits on the numbers
5.random_numbers(:from => 1, :to => 5)
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/rujitsu/fixnum.rb', line 27 def random_numbers( opts = {} ) # Then set some defaults, just in case upper = opts[:to] || 9 lower = opts[:from] || 0 only = opts[:only] || :both # And finally calculate the number n = [] (self - 1).times do i = (lower..upper).to_a.sort_by { rand }.first n << i.to_s end # add the last digit according to :only n << end_number_choices(only).select {|x| (lower <= x) && (x <= upper) }.sort_by { rand }.first.to_s n.join("") end |
#random_vowels(opts = {}) ⇒ Object Also known as: random_vowel
produce a string of N random vowels
5 6 7 |
# File 'lib/rujitsu/fixnum.rb', line 5 def random_vowels opts={} generate_random_string_using VOWELS, opts end |