Class: MemorableStrings::Vowel

Inherits:
Phoneme
  • Object
show all
Defined in:
lib/memorable_strings/vowel.rb

Overview

Represents a phoneme that begins with a vowel letter

Instance Attribute Summary

Attributes inherited from Phoneme

#length, #value

Instance Method Summary collapse

Methods inherited from Phoneme

add, first, #first?, #initialize, #matches?, #print_friendly?, random

Constructor Details

This class inherits a constructor from MemorableStrings::Phoneme

Instance Method Details

#next(stack, maxlength, &block) ⇒ Object

Generates a phoneme of at most the given length that should follow this vowel.

If the last two characters in the stack (including this one) were vowels, then this will always generate a consonant. Otherwise, 40% of the time it will generate a single-character vowel and 60% of the time it will generate a consonant.

It is never possible for two consecutive vowel phonemes to result in more than 2 vowel characters in the stack.



16
17
18
19
20
21
22
23
# File 'lib/memorable_strings/vowel.rb', line 16

def next(stack, maxlength, &block)
  previous = stack[-2]
  if previous && previous.is_a?(Vowel) || length > 1 || rand(10) > 3
    Consonant.random(1, &block)
  else
    Vowel.random(1, &block)
  end
end