Ruby - Enumerable - collect

  • + 0 comments
    def rot13(secret_messages)
        secret_messages.map {
            |msg| decipher_message(msg)
        }
    end
    
    def decipher_message(msg)
        msg.chars.map { |c|
            case c
                when 'a'..'m', 'A'..'M'
                    (c.ord + 13).chr
                when 'n'..'z', 'N'..'Z'
                    (c.ord - 13).chr
                else
                    c
            end
        }.join
    end