Class: Fixnum

Inherits:
Object show all
Defined in:
lib/rujitsu/fixnum.rb

Instance Method Summary collapse

Instance Method Details

#random_characters(opts = {}) ⇒ Object

produce a string of N random characters

5.random_characters


37
38
39
# File 'lib/rujitsu/fixnum.rb', line 37

def random_characters opts={}
  generate_random_string_using CHARACTERS, opts
end

#random_consonants(opts = {}) ⇒ Object

produce a string of N random consonants



7
8
9
# File 'lib/rujitsu/fixnum.rb', line 7

def random_consonants opts={}
  generate_random_string_using CONSONANTS, opts
end

#random_letters(opts = {}) ⇒ Object

produce a string of N random letters

5.random_letters


12
13
14
# File 'lib/rujitsu/fixnum.rb', line 12

def random_letters opts={}
  generate_random_string_using LETTERS, opts
end

#random_numbers(opts = {}) ⇒ Object

produce a string of N random numbers

5.random_numbers

optionally specific limits on the numbers

5.random_numbers(:from => 1, :to => 5)


19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/rujitsu/fixnum.rb', line 19

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

 produce a string of N random vowels



3
4
5
# File 'lib/rujitsu/fixnum.rb', line 3

def random_vowels opts={}
  generate_random_string_using VOWELS, opts
end