Skip to content

Instantly share code, notes, and snippets.

@ahimmelstoss
Created October 7, 2013 14:51
Show Gist options
  • Save ahimmelstoss/6869285 to your computer and use it in GitHub Desktop.
Save ahimmelstoss/6869285 to your computer and use it in GitHub Desktop.
anagram class using chars.sort to match a word's anagram in an array of words. chars.sort sorts the characters in a string.
class Anagram
attr_accessor :word
def initialize(word)
@word = word
end
def match(words_array)
words_array.select {|element| element.chars.sort == @word.chars.sort}
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment