exercism/ruby/anagram/anagram.rb

19 lines
308 B
Ruby
Raw Normal View History

2018-10-24 10:41:13 -04:00
# Anagram class
class Anagram
def initialize(word)
@word = word.downcase
end
def match(candidates)
2018-10-24 10:57:41 -04:00
candidates.select do |candidate|
sorted(@word) == sorted(candidate) && @word != candidate.downcase
end
end
private
def sorted(word)
word.downcase.chars.sort.join
2018-10-24 10:41:13 -04:00
end
end