Class: Alphabetize

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#alphabetObject

set the alphabet as a string using this accessor Ex. x = Alphabetize.new x.alphabet = “abcĉdefgĝhĥijĵklmnoprsŝtuŭvz”



9
10
11
# File 'lib/alphabet_soup/alphabet_class.rb', line 9

def alphabet
  @alphabet
end

Instance Method Details

#alphabetize(arr) ⇒ Object

takes an array of strings as an argument and orders them alphabetically based on the alphabet set using the alphabet accessor



14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/alphabet_soup/alphabet_class.rb', line 14

def alphabetize(arr)
  arr.sort_by do |word| 
    word.split("").collect do |letter| 
      split_alphabet = alphabet.split("")
      if split_alphabet.include?(letter)
        split_alphabet.index(letter)
      else
        split_alphabet.count
      end
    end
  end
end