FAQ: Redacted! - The .split Method

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

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

Learn Ruby

FAQs on the exercise The .split Method

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!

Hello,

I’m struggling with this one!

puts “The World Is Yours!”
puts “i will make you a offer that you can refuse!”
text = gets.chomp
redact = gets.chomp
words = text.split (" ")

ERROR! It looks like you didn’t use the .split method to make words an array.

Can some one help me? Many thanks in advance!

1 Like

maybe you should change the order?
like

puts “The World Is Yours!”
text = gets.chomp
puts “i will make you a offer that you can refuse!”
redact = gets.chomp
words = text.split (" ")

Hi there! So here’s the thing, the way this programme is made, if we want to redact a word close to a comma or dot, or anything else other than a blank space, it won’t work. For instance, if I write “Hello!” and I want to redact “Hello”, things will remain the same. So my question is, can I apply the split method at different criteria simultaneously, this is, to split every time it sees a blank space, a dot, a comma and an exclamation mark? Thanks!

Welcome, @design4743405018,

This is an interesting question that has come up before, within a slightly related topic…

Attempting to redact multiple words

Read through the topic and the discussion centered around using a Regex to spot word boundaries (around post 55 and beyond).

I am having trouble with running the code in this exercise. I can input text at the first prompt, but then the console terminates with the error “execution expired”.

I am able to reproduce this error when I run the solution code, as well.

I’ve oft repeated this suggestion: Forget about the input, and supply values for those variables. Then you can at least run the code and see what it does.

Chances are very good that your code runs as expected in a REPL.it sandbox. This environment is wonky when it comes to user input. Some users have workaround suggestions or browser change, etc. You can still pass if you hard code the values.

I can’t run anything at all on this step of the exercise, not even the first line, without getting the execution expiration error.

I advanced forward by viewing the solution code. The same error occurs again on the next page, but I was finally able to run the code after a few browser refreshes.

This poster from April has identified the same problems I’m experiencing.

1 Like

What if we Reset and enter just this code?

text = "Always butter the burnt side of the toast"
words = text.split()
z = text.dup
redact = "burnt side"
redact.split(' ').each {|x| z.gsub! /\b#{x}\b/i, "REDACTED"}
puts z
2 Likes

This exercice still doesn’t work, I have to hardcode the strings.
The chomps have a problem.