Skip to content

Instantly share code, notes, and snippets.

@shepmaster
Forked from alekst/gist:6436407
Last active December 22, 2015 07:18
Show Gist options
  • Save shepmaster/6436533 to your computer and use it in GitHub Desktop.
Save shepmaster/6436533 to your computer and use it in GitHub Desktop.
class AnagramTest < MiniTest::Unit::TestCase
class Anagram
def initialize(word)
@word = word
@anagram = Array.new
end
def match(candidates)
candidates.each do |candidate|
if candidate.turning_into_letters == @word.turning_into_letters
@anagram << candidate unless candidate.downcase == @word
end
end
@anagram
end
end
end
class String
def turning_into_letters
self.downcase.chars.sort
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment