I am going through the Odin Project Ruby section, and just finished implementing a Caesar cipher interpretation. Should I use classes, or more than one method to distribute the flow? Is there really a need for initialization in this?
def caesar_cipher(string, shifter)
ciphered = []
string.split("").each do |char|
if char == " " then ciphered << char
next
end
char = char.to_s.ord
if ("a".ord.."z".ord).include? char
if char + shifter < "z".ord
ciphered.push((char + shifter).chr)
else
ciphered.push((shifter - ("z".ord - char) + "a".ord).chr)
end
elsif ("A".ord.."Z".ord).include? char
if char + shifter < "Z".ord
ciphered.push((char + shifter).chr)
else
ciphered.push((shifter - ("Z".ord - char) + "A".ord).chr)
end
else
next
end
end
print ciphered.join + "\n"
end
#test: caesar_cipher("Hello friend my Name is Sam",10)