Classnamer

Classnamer randomly generates tongue-in-cheek class names suitable for enterprise-friendly object-oriented programming languages like C++ and Java. It includes a library and a command-line program.

This code is packaged as a RubyGem and tested on the following branches of MRI (Matz’s Ruby Interpreter): 1.8.7, 1.9.3, 2.0.0, 2.1.x, and 2.2.x.

Using the command-line program

$ classnamer
PrioritizedUploadWrapper

Using in Ruby code

You can generate a random class name like this:

require 'classnamer'
puts Classnamer.generate # => PrioritizedUploadWrapper

You can customize how class names are generated. Classnamer will generate random class names by concatenating randomly-selected elements of arrays that you provide.

puts Classnamer.generate([%w{Foo Bar}, %w{Baz Qux}]) # => FooQux

You can also specify a custom random number generator. Maybe you don’t even want it to be random.

puts Classnamer.generate([%w{Foo Bar}, %w{Baz Qux}], lambda { |_| 0 })
  # => FooBaz

If you plan to use the same customizations multiple times, you can create a Classnamer::Generator object for that.

generator = Classnamer::Generator.new([%w{Foo Bar}, %w{Baz Qux}])
generator.generate # => FooQux
generator.generate # => BarQux

Author

This was written by Aaron Beckerman.

Acknowledgements

Thanks to Luiz Signorelli and Marta Paciorkowska for their suggestions.

This code is distributed under the MIT License (also known as the Expat License). See the LICENSE.txt file for details.