Class: Pluralizer

Inherits:
Object
  • Object
show all
Defined in:
lib/pluralizer.rb

Overview

The main Pluralizer class

Class Method Summary collapse

Class Method Details

.is_vowel(letter) ⇒ Object



32
33
34
35
36
37
38
# File 'lib/pluralizer.rb', line 32

def self.is_vowel(letter)
  if letter == "a" || letter == "e" || letter == "i" || letter == "o" || letter == "u"
    true
  else
    false
  end
end

.pluralize(word) ⇒ String

Examples:

>> Pluralizer.pluralize(book)
=> books

>> Pluralizer.pluralize(bunny)
=> bunnies

Parameters:

  • word (String)

    to be pluralized

Returns:

  • (String)

    word in plural form



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/pluralizer.rb', line 14

def self.pluralize(word)
  if is_vowel(word[-2,1]) && word[-1,1] == "y"
    puts word + "s"
  elsif is_vowel(word[-2,1]) == false && word[-1,1] == "y"
    puts word[0, word.length - 1] + "ies"
  elsif is_vowel(word[-2,1]) && word[-1,1] == "o"
    puts word + "s"
  elsif is_vowel(word[-2,1]) == false && word[-1,1] == "o"
    puts word + "es"
  elsif word[-2,2] == "fe" || word[-1,1] == "f"
    puts word[0, word.length - 1] + "ves"
  elsif word[-1,1] == "s" || word[-2,2] == "ss" || word[-2,2] == "sh" || word[-2,2] == "ch" || word[-1,1] == "x" || word[-1,1] == "z"
    puts word + "es"
  else
    puts word + "s"
  end
end