Problem Redacted


Hi everyone,
I successfully passed this lesson with this :

puts "Tell me something"
text = gets.chomp
puts "What do you want to hide ?"
redact = gets.chomp

words = text.split(" ")

words.each do |word|
if word == redact
print "REDACTED "
print word + " "

But I want to apply this as well "How could you make your program take multiple, separate words to REDACT?"

and I was thinkin' of calling a split method on the string redact so that i can have an array of the user input words that he wants to hide but I just don't know how to hide those inputs all at once... any advice ?


Yeah, basically you're going to need to split your input just as you do with the original text.

Then you'll need a way to know if your current word is inside this new split, for example using the include? method.

The rest is similar.


so is it this :
redactss = redact.split(" ")

if redactss.include? (words)
puts "redacted"



You're asking include? to look for an array inside an array of strings there. I doubt it will work. You need to look for a string inside an array of strings.


ah I think I get it
so is it redactss.include?(redact)
Here I'm asking include? to look into the array newly created "redactss" if there is any words that the user wanted to hide, and we know that the words that the user wanted to hide are in the redact variable right...?


redactss contains the same data as redact remember? It's just that redactss is an array of strings while redact is a string.

So looking for a data inside the same data will always give you a positive result. (actually it won't, because the string is different and far longer than the ones inside the array ^^)

In what variable is the text stored?


(post withdrawn by author, will be automatically deleted in 24 hours unless flagged)


ah the text is stored in the words variable
so it is words.include?(redact) i suppose...


You want to search inside words now?

You have your each loop which already scans through words, why do you want to look through words again?

Your include? will be on redactss, now, which variable containing a string (so not an array) will you want to look for inside redactss?

Redacted 6/6 Understanding Problem

redactss.include?(text) ..? i think it is that..
I'm sorry I feel like an idiot


You're not an idiot you're trying to learn, there's nothing idiotic in that.

text would be fine except that it's a string which has all the words, so it will never be found.

Which string variable has all words, but only one each time?


It's word because it tooks every words from the array words and delivers it one each time
phew sorry for my english


Yes, it's word.

Now that you have your redactss.include?(word), how will it fit inside your code?

Try a version you think is correct and run it.


That worked !!

words.each do |word|
if word == redact
print "REDACTED "

    print word + " "
else redacts.include?(word)
    print "REDACTED"


Thank you so much arjofocolovi ! :smile:
greetings from France!


That's great, congratz.

But now you don't need the first if anymore, since you have all your redact words inside the redacts array.

words.each do |word|
    if redacts.include?(word)
    print "REDACTED "
    print word + " "

This should be enough. But it's good that you made it work, good luck for the rest of the course.


the first end is to close the do loop, the second end is to close the if loop. The text you are seeing duplicated is because ruby IRB will print out whatever the object from the last action in your method. This is why you often see 'nil' at the end of a codecademy lesson.

What is the problem that is frustrating you? the solution above is solid.


I don't want to use .include? or any other coding that has not already been taught in the lesson. When I use words.each do |word| it says that word is not defined. Is it just an error or I'm missing something?


Hi Wolflash,

.include? was taught way back in lesson 3, it is how you built the regular text --> daffy duck text. It is not something new to be afraid of. I will be blunt and say that your stubbornness is making you close minded to good advice - we are trying to help. If you can take a moment to reflect, you will see that you have made multiple boldly incorrect statements in your posts which others have tried to correct for you.

  1. There should be 2 ends, you are using 2 blocks.
  2. The end does not cause duplication, thats a feature of ruby called 'implicit return'.
  3. .include? has been taught, regardless it is not related to your problem.

Can you please post your full set of code for this exercise rather than just the single line for the do loop. This will help us guide you in fixing your problem. If I had to take a guess, I would say that you are getting 'word not defined' because you are passing an incorrect object type. Words should be an array, which is what allows word to be the element we will iterate on.



It doesn't ask to use include? though, and I'd post my code, but I'm concerned with indentation & such. I would post my code if I knew how to do it correctly. I'm not close-minded, I'm tired. I'm not a professional, and I'm [not] giving excuses. I don't remember using end twice to complete two different loops inside each other. Now I'll go over previous lessons to correct my bold mistakes

What about word being defined? I am not wrong about that. Perhaps it is an error personally for me.

(edit)- looking at Data Structures.12, I see in the hint end being used twice. Thank you for taking the time to explain

I'm not bold or afraid either, I'm introverted.



To properly post your code, use the </> icon above your text box when you answer (near the emoticons and other stuff.

if x > 0
print "yolo"
print "yili"

I don't know how to indent it though.

Anyway, did you solve your issue in the end?