FAQ: Redacted! - Redacted!

This community-built FAQ covers the “Redacted!” exercise from the lesson “Redacted!”.

Paths and Courses
This exercise can be found in the following Codecademy content:

Learn Ruby

FAQs on the exercise Redacted!

There are currently no frequently asked questions associated with this exercise – that’s where you come in! You can contribute to this section by offering your own questions, answers, or clarifications on this exercise. Ask or answer a question by clicking reply (reply) below.

If you’ve had an “aha” moment about the concepts, formatting, syntax, or anything else with this exercise, consider sharing those insights! Teaching others and answering their questions is one of the best ways to learn and stay sharp.

Join the Discussion. Help a fellow learner on their journey.

Ask or answer a question about this exercise by clicking reply (reply) below!

Agree with a comment or answer? Like (like) to up-vote the contribution!

Need broader help or resources? Head here.

Looking for motivation to keep learning? Join our wider discussions.

Learn more about how to use this guide.

Found a bug? Report it!

Have a question about your account or billing? Reach out to our customer support team!

None of the above? Find out where to ask other questions here!

Hi there!

I’m confused about the usage of the .each method here. From my understanding the .each method allows you to add expressions to each element of an object one at a time. But in this case it’s doing something else. I would greatly appreciate some clarification about the .each method.

Thank you!

.each is simply an iterator. In this exercise, the user’s inputted string literal is converted to an array using the .split() method. Then we use .each to iterate through the array one word at a time. We can then perform any number of actions using the word. In this case we compare it to the word we want to redact, and if it is the same, we print 'REDACTED ' instead of the word. We are not constrained to actions that manipulate each word in some way. The .each method lets us perform actions involving each element of an object not necessarily on the element itself. Hope that made sense.


That helps a lot, thank you for your response, i really appreciate it!

1 Like

words.each { |word| print word }

1 Like

Hi, I’m confused as I’ve followed what’s in the hint exactly, and it’s not working. I’m also confused by the use of an array in the text higher up the page - I think I might be overthinking this again.
Also, for feedback - putting “Let’s start simple” is really unhelpful, as now I’m getting this wrong I feel like I’m stupid. It’s not simple if you don’t know how to do it.
I had the previous code all fine, and I’ve added:
words.each { |word| print word }
This matches the hint exactly in syntax, so I’m expecting it to work.


Barring any other issues, the code you’ve shown in your post should work. If you’d like to post your entire code for this lesson, we can see if there might be another issue. If you’re sure the code is correct, try refreshing your browser, and see if that helps. Good luck!

Hi, so I’ve gone back in today (was busy all day yesterday) and tried it fresh. Same result.
Complete code is:
text = “Things to look at.”
text = gets.chomp

redact = “Things to redact.”
redact = gets.chomp

words = text.split(" ")
words.each { |word| print word }

And the error message is:
(ruby):8: syntax error, unexpected keyword_end, expecting end-of-input

I looked at the solution, and it’s phrased in a different way that works. I still don’t understand why what I’ve written doesn’t work, but I’ve moved in.
It seems to be that, in a few places, the hint uses a different way of doing it to the solution, which frankly doesn’t help me learn where I’ve gone wrong by trying to follow the hint.

Sorry for the late reply. The issue is that you used the keyword end You can either use curly braces { } or do ... end, but you can’t use parts of each together. So either of these two examples will work:

words.each do |word|
  #do stuff here


words.each {|word|
  #do stuff here

Hope this helps!


So, i finally got stucked and can’t seem to move on from this exercise.

What they ask us to do:

Let’s start simple: write an .each loop that iterates through words and just print s out each word it finds.

This is what i’ve got so far:

puts “text”
puts “redact”

words = text.split(" ")

this is the new part that’s not working:

words.each { |words|
print words

This is what I get:
undefined local variable or method `text’ for #Context:0x84d76c
Did you mean? test

Can anybody tell me what am I doing wrong?

Hello, @tagrunner21975.

Welcome to the forums.

It looks like you are wanting to assign user input to the variables text and redact. You may want to quickly review how to do that here.
Hint: The assignment operator = is a necessary component. :wink: