Module: Classnamer
- Defined in:
- lib/classnamer.rb
Overview
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.
Defined Under Namespace
Classes: Generator
Constant Summary collapse
- VERSION =
The library’s version string.
"3.0.13"- PART_CANDIDATE_MATRIX =
The default part candidate matrix, used by generate.
[ %w{Threadsafe Optimized Stable Automatic Abstract Serializable Writable Readable Blocking Nonblocking Scriptable Smart Basic Remote Simple Secure Cryptographic Flexible Configurable Internal Cloneable Legacy Recursive Multiple Threaded Virtual Singleton Stateless Stateful Localized Prioritized Generic Dynamic Shared Modal Fast Temporary}, %w{Byte Task Object Resource Mutex Memory List Node File Lock Pixel Character Command Client Server Socket Thread Notification Keystroke Timestamp Raster String Hash Integer Cache Scrollbar Grid Package Connection Database Graph Row Column Record Metadata Transaction Message Request Response Query Statement Result Upload Download User Directory Button Device Search Lolcat Robot}, %w{Sorter Allocator Tokenizer Writer Reader Randomizer Initializer Factory Panel Frame Container Compressor Expander Counter Collector Collection Wrapper Accumulator Table Marshaller Demarshaller Extractor Parser Scanner Interpreter Validator Window Dialog Stream Listener Event Exception Vector Lexer Analyzer Iterator Set Tree Concatenator Monitor Tester Buffer Selector Visitor Adapter Helper Annotation Permission Info Action Channel Filter Manager Mediator Operation Context Queue Stack View Engine Publisher Subscriber Delegator State Processor Handler Generator Dispatcher Bundle Builder Logger Iterator Observer Encoder Decoder Importer Exporter Util Policy Preference Formatter Sequence Comparator Definition Timer Classifier Controller Loader Converter Constraint Module Migrator Descriptor Process} ]
- PRNG =
The default index generator, used by generate.
::Kernel.method :rand
Class Method Summary collapse
-
.generate(matrix = PART_CANDIDATE_MATRIX, prng = PRNG) ⇒ Object
Randomly generates a class name and returns it.
Class Method Details
.generate(matrix = PART_CANDIDATE_MATRIX, prng = PRNG) ⇒ Object
Randomly generates a class name and returns it. This method 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 will be sent call messages with one integer argument (an array length) and must act like Kernel::rand with an integer argument.
59 60 61 |
# File 'lib/classnamer.rb', line 59 def self.generate matrix = PART_CANDIDATE_MATRIX, prng = PRNG matrix.map { |a| a[prng.call a.length] }.join "" end |