Skip to content

Instantly share code, notes, and snippets.

@leandroh
Created June 7, 2017 23:01
Show Gist options
  • Save leandroh/dba786bc48e4a2a602e11f2507ebaa12 to your computer and use it in GitHub Desktop.
Save leandroh/dba786bc48e4a2a602e11f2507ebaa12 to your computer and use it in GitHub Desktop.
Check if two words are anagram in Ruby
class Anagram
def is_anagram?(one, other)
one.downcase.chars.sort.join == other.downcase.chars.sort.join
end
end
require 'minitest/autorun'
describe Anagram do
before do
@anagram = Anagram.new
end
describe '.is_it?' do
describe 'when asked if it is an anagram' do
it 'must respond positively' do
one = 'amor'
other = 'roma'
@anagram.is_anagram?(one, other).must_equal true
end
end
describe 'when asked if a capital letter is an anagram' do
it 'must respond positively' do
one = 'Celia'
other = 'Alice'
@anagram.is_anagram?(one, other).must_equal true
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment