Module: Hammock::StringPatches::ClassMethods

Defined in:
lib/hammock/monkey_patches/string.rb

Instance Method Summary collapse

Instance Method Details

#af09(length = 1) ⇒ Object

Generates a random string consisting of length hexadecimal characters (i.e. matching [0-9a-f]length).



13
14
15
16
17
# File 'lib/hammock/monkey_patches/string.rb', line 13

def af09 length = 1
  (1..length).inject('') {|a, t|
    a << rand(16).to_s(16)
  }
end

#azAZ09(length = 1) ⇒ Object

Generates a random string consisting of length alphamuneric characters (i.e. matching [0-9a-zA-Z]length).



20
21
22
23
24
# File 'lib/hammock/monkey_patches/string.rb', line 20

def azAZ09 length = 1
  (1..length).inject('') {|a, t|
    a << ((r = rand(62)) < 36 ? r.to_s(36) : (r - 26).to_s(36).upcase)
  }
end