DEV Community

Discussion on: Write a script to identify an anagram

 
ben profile image
Ben Halpern • Edited

Looking up methods on the Array class, I see that I can refactor the above to:

def are_anagrams?
    self.map { |w| sort_alphabetically(w) }.uniq.one?
end

This may be less clear to non-Rubyists, but that method is there for a reason for Ruby folks.

Thread Thread
 
mtbsickrider profile image
Enrique Jose Padilla

Following your train of thought was fun

Thread Thread
 
xelaflash profile image
xelaflash

Very cool
i'm learning ruby currently and the refactor steps are very clear and easy to follow.
At then end only one line method!
i would have written this in 20 lines probably and in a couple of hours :)

Cool stuff.