Skip to content

Instantly share code, notes, and snippets.

@eternal44
Created August 21, 2015 23:44
Show Gist options
  • Save eternal44/450f1b7d72599aa01e57 to your computer and use it in GitHub Desktop.
Save eternal44/450f1b7d72599aa01e57 to your computer and use it in GitHub Desktop.
Refactored exercise
# doctest: correct output
# >> split_message("Welcome to the forum.\nHere you can learn Ruby.\n"\
# "Along with other members.\n")
# => ["Line 1: Welcome to the forum.", "Line 2: Here you can learn Ruby.", "Line 3: Along with other members."]
def split_message(message)
message.split("\n").collect.with_index { |i, j| "Line #{j + 1}: " + i }
end
split_message("Welcome to the forum.\nHere you can learn Ruby.\n"\
"Along with other members.\n")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment