Skip to content

Instantly share code, notes, and snippets.

@damianesteban
Created April 4, 2014 17:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save damianesteban/9978871 to your computer and use it in GitHub Desktop.
Save damianesteban/9978871 to your computer and use it in GitHub Desktop.
# Given a string, replace every instance of sad to happy
#
# add_more_ruby("The clowns were sad.") # => "The clowns were happy."
# add_more_ruby("The sad dad said sad stuff.") # => "The happy dad said happy stuff."
# add_more_ruby("Sad times are ahead!") # => "Happy times are ahead!"
def add_more_ruby(string)
string.gsub(/[sS]ad/, 'sad' => 'happy', 'Sad' => 'Happy')
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment