Skip to content

Instantly share code, notes, and snippets.

@nextacademy-private
Created August 31, 2014 09:07
Show Gist options
  • Save nextacademy-private/28e7792a00684332b97c to your computer and use it in GitHub Desktop.
Save nextacademy-private/28e7792a00684332b97c to your computer and use it in GitHub Desktop.
def destroy_message(string)
#TODO: return the part a string without the message
end
def destroy_message!(string)
#TODO: remove the message from string destructively!
end
# Driver code...
string = "this message will self-destruct: you can't hug every cat"
original_string = string.dup
puts destroy_message(string) == "this message will self-destruct:"
puts string == original_string # we shouldn't modify the string passed to destroy_message
string = "this has no message"
original_string = string.dup
puts destroy_message(string) == string
puts string == original_string # we shouldn't modify the string passed to destroy_message
string = "this message will self-destruct: you can't hug every cat"
original_string = string.dup
destroy_message!(string)
puts string == "this message will self-destruct:"
puts string != original_string
string = "this has no message"
result = destroy_message!(string)
puts result.nil?
puts string == string
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment