module Classnamer

This module randomly generates class names, such as “PrioritizedUploadWrapper”. It does this by concatenating several parts (“Prioritized”, “Upload”, and “Wrapper”, in this case), which are strings randomly selected from arrays of candidates. (“Prioritized”, “Upload”, and “Wrapper” were each selected from a different array.) An array of such arrays is called a part candidate matrix.

Constants

PART_CANDIDATE_MATRIX

The default part candidate matrix, used by generate.

PRNG

The default index generator, used by generate.

VERSION

The library's version string.

Public Class Methods

generate(matrix = self::PART_CANDIDATE_MATRIX, prng = self::PRNG) click to toggle source

This method does the actual work of randomly generating a class name. It takes two arguments, both optional: a part candidate matrix (matrix) and an index generator (prng). If matrix is not specified, the module's default part candidate matrix (PART_CANDIDATE_MATRIX) is used. If prng is not specified, Kernel::rand is used. matrix must act like an array of arrays of strings. prng must have a “call” method that takes one integer argument (an array length) and acts like Kernel::rand.

# File lib/classnamer.rb, line 49
def self.generate(matrix = self::PART_CANDIDATE_MATRIX, prng = self::PRNG)
  matrix.map { |a| a[prng.call a.length] }.join ''
end