I can write multiple functions to handle many conditions. Otherwise, in Ruby, I often use if else.
def rotate(text, shift) do
text |> to_charlist |> Enum.map(fn(item)-> shift_char(item, shift) end) |> to_string
end
# 3 different functions to handle multiple conditions( ?a..?z, ?A..?Z and special characters)
defp shift_char(char, shift) when char in ?a..?z do
shift_char_with_base(char, shift, ?a)
end
defp shift_char(char, shift) when char in ?A..?Z do
shift_char_with_base(char, shift, ?A)
end
defp shift_char(char, _) do
char
end
if else
.