exercism/ruby/anagram/anagram.rb
2018-10-24 10:57:41 -04:00

19 lines
308 B
Ruby

# Anagram class
class Anagram
def initialize(word)
@word = word.downcase
end
def match(candidates)
candidates.select do |candidate|
sorted(@word) == sorted(candidate) && @word != candidate.downcase
end
end
private
def sorted(word)
word.downcase.chars.sort.join
end
end