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

15 lines
349 B
Ruby

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