fork(1) download
  1. def caesar_cipher(str, key)
  2. str1 = str.split(//)
  3. str1.map! do |ch|
  4. if (/\w/.match(ch))
  5. key.times do
  6. if (/^[zZ]/.match(ch))
  7. ch.next!
  8. elsif (/z/.match(ch))
  9. ch = "a"
  10. else
  11. ch = "A"
  12. end
  13. end
  14. end
  15. end
  16. str1.join
  17. end
  18.  
  19. puts caesar_cipher("What a string!", 4)
Success #stdin #stdout 0.05s 9704KB
stdin
Standard input is empty
stdout
44444444444