Welcome to the Treehouse Community
Looking to learn something new?
Hossam Khalifa17,200 Points
Ruby String equality
I created a method that dose some basic encryption,changing every letter in a string to next letter. The method works but when I try to compare the string that is returned by the method to the string that should be returned it returns false.
here is the code:
def caesar_cipher(string,int) chars = string.chars int.times do chars.each do |char| if ("a".."z") === char char.next!() end end end puts chars.join chars.join end x = caesar_cipher('What a string!', 5) puts x.length == "Bmfy f xywnsl!".length #=> true puts x == "Bmfy f xywnsl!" #=> false =>WHY??
Kevin Korte28,109 Points
So x is actually equal to Wmfy f xywnsl!, and so when you change the B to W it will return true.