Last active
February 11, 2018 11:50
-
-
Save ricardotealdi/8b7c043ab8393c5930db to your computer and use it in GitHub Desktop.
Simple Pronounceable Word Generator in Ruby
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class WordGenerator | |
VOGALS = %w(a e i o u y) | |
CONSONANTS = [*?a..?z] - VOGALS | |
MOD_RESULT = [0, 1].freeze | |
def initialize(length) | |
@length = length | |
@mod_result = MOD_RESULT.sample | |
end | |
def generate | |
length.times.map { |i| i % 2 == mod_result ? CONSONANTS.sample : VOGALS.sample }.join | |
end | |
private | |
attr_reader :length, :mod_result | |
end | |
# 100.times.each { puts WordGenerator.new(10).generate } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment