誰かがこの行で何が起こっているのか簡単に説明してもらえますか:
new_word += alphabet[alphabet.index(i.downcase) - num]
new_word = new_word 変数の現在の状態 + 何?
これはプログラム全体です:
def cipher(word, num)
alphabet = ('a'..'z').to_a.concat(('A'..'Z').to_a)
new_word = ""
word.each_char do |i|
if !alphabet.include?(i)
new_word +=i
else
new_word += alphabet[alphabet.index(i.downcase) - num]
end
end
return new_word.downcase.capitalize
end
puts cipher("Apples? and Oranges!", 2)