Redact text from a file


#1

I have a question to many smarter then me..

I managed to get my code to read text from a file, convert the text into a string & put all the words into an array.
Now when launching my code it seems to skip over the part where it's supposed to ask me what word to redact.. can anyone shed some light to why this is happening ?

My code so far is as follows :

filename = ARGV.first
file = open(filename)
file = file.read

puts "Fail analüüsimiseks: #{filename}"

redacted = puts "Märksõna salastamiseks: "
redacted = gets.chomp

words = file.split(" ")

words.each do |x| 
    if x.downcase == redacted.downcase
        print "SALASTATUD "
    else 
        print x + " "
    end
end

#2

Well it turns out that had to use $stdin with gets.chomp
As in :

filename = ARGV.first
file = open(filename)
file = file.read

puts "Fail analüüsimiseks: #{filename}"

redacted = puts "Märksõna salastamiseks: "
redacted = $stdin.gets.chomp

words = file.split(" ")

words.each do |x| 
if x.downcase == redacted.downcase
print "SALASTATUD "
else 
print x + " "
end
end