Skip to content

Instantly share code, notes, and snippets.

@stevencombs stevencombs/Redacted.rb
Last active Dec 26, 2015

What would you like to do?
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
You can’t perform that action at this time.