Class: String

Inherits:
Object show all
Defined in:
lib/core_ext/string.rb

Class Method Summary collapse

Class Method Details

.mkpasswd(length: 16) ⇒ Object

Generates a password

Examples:

String.mkpasswd # => "ZCLXangKu7xFk4SN"
String.mkpasswd(length: 8) # => "av7AGr8q"

Parameters:

  • options (Hash)

8
9
10
11
# File 'lib/core_ext/string.rb', line 8

def self.mkpasswd(length: 16)
  chars = (('A'..'Z').to_a + ('a'..'z').to_a + ('0'..'9').to_a)
  Array.new(length){ chars[rand(chars.size)] }.join('')
end