Skip to content

Instantly share code, notes, and snippets.

@stevencombs
Last active December 26, 2015 22:39
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 stevencombs/7224802 to your computer and use it in GitHub Desktop.
Save stevencombs/7224802 to your computer and use it in GitHub Desktop.
Request multi word input and request a word to redact from the input. Redacted word will be replaced with "REDACTED" unless word to redact was not found in which case the string will print intact.
# Ruby Getting Started with Programming
# A Codecademy Ruby (Redacted) assignment
# Dr. Steven B. Combs, coding novice
puts "Text to search through: " #Puts text
text = gets.chomp #Request input and "chomp" return
puts "Word to redact: " #Puts text
redact = gets.chomp #Request second input and "chomp" return
words = text.split (" ") #Splits the input into words at each space
words.each do |word| #Loop for each word in variable words and place word in variable word
if word != redact #If word (from split of words) is not equal to "redact"
print word + " " #Print word and a space (used to separate the splits)
else #If words split is equal to the redact word
print "REDACTED " #Print "REDACTED" in place of the word
end #End if
end #End .each loop
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment