Skip to content

Instantly share code, notes, and snippets.

@dmerrick
Created February 13, 2015 22:43
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 dmerrick/f7e518fdc5337d497e81 to your computer and use it in GitHub Desktop.
Save dmerrick/f7e518fdc5337d497e81 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
puts "Why is the FBI after you?"
# optional, but you can chain the downcase here
text = gets.chomp.downcase
# the default parameter for String#split is ' ', so you can omit it
words = text.split
# note that since text was only used here, you could have just said:
#words = gets.chomp.downcase.split
puts "What information needs to be destroyed?"
redact = gets.chomp.downcase
# I'm going to go different way this time, I'm going to create an array
# which I will use to build the final string
final_words = []
words.each do |word|
if word == redact
# put REDACTED into the array
final_words.push('REDACTED')
else
# otherwise, put the uncensored word into the array
final_words.push(word)
end
end
# finally, display the string
puts final_words.join(' ')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment