Skip to content

Instantly share code, notes, and snippets.

@marksim
Created July 25, 2013 15:54
Show Gist options
  • Save marksim/6081139 to your computer and use it in GitHub Desktop.
Save marksim/6081139 to your computer and use it in GitHub Desktop.
class Anagram < Struct.new(:base)
def match(candidates)
candidates.select do |candidate|
word.anagram?(candidate)
end
end
def word
@word ||= AnagramWord.new(base)
end
end
class AnagramWord < String
def anagram?(word)
sorted == AnagramWord.new(word).sorted
end
def sorted
chars.sort
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment