Skip to content

Instantly share code, notes, and snippets.

@pzula
Last active December 25, 2015 07:19
Show Gist options
  • Save pzula/6938430 to your computer and use it in GitHub Desktop.
Save pzula/6938430 to your computer and use it in GitHub Desktop.
Anagram shenanagins
class Anagram
attr_reader :starting_word
def initialize(starting_word)
@starting_word = starting_word
end
def starting_letters
starting_word.chars
end
def starting_letters_alphabetized
starting_letters.sort
end
def match(comparison_words)
matches = []
comparison_words.each do |word|
if equal_length?(word) && not_the_same_word?(word) && same_characters?(word)
matches << word
end
end
return matches
end
def equal_length?(word)
starting_word.length == word.length
end
def not_the_same_word?(word)
starting_word != word
end
def same_characters?(word)
word.chars.sort == starting_letters_alphabetized
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment