Note that there are some explanatory texts on larger screens.

plurals
  1. PORuby redaction program logic?
    primarykey
    data
    text
    <p>Okay, I am doing the codeacademy ruby track and I am not stock with the problem. I can make it works now, but I don't understand why it works. instructions for exercise:</p> <blockquote> <p>Let's start simple: write an .each loop that goes through words and just prints out each word it finds.</p> </blockquote> <p>I have broken the problem into steps to try to understand why it works but I am very confused. My code for the problem is:</p> <pre><code>puts "Text to search through: " #ask user for input text = gets.chomp #store the user's input into the variable text puts "Text to be reducted: " #ask the user for input redact = gets.chomp #store the user's input into the variable redact words = text.split(" ") =begin split the user's input into the variable words store that input into the variable words =end words.each do |word| =begin creates a placeholder for the user's input then attach an expression to the input stored in the variable words one at a time. The variable words holds the value of the variable text =end if word != redact =begin if word (which now holds the value of words that's stored in the variable text, and which is the user's input) is not equal to the value of the variable redact do something =end word = word + " " =begin increment the value of word by an empty space why do I need to increment the value of word by an empty space? =end print "#{word}" #print the value of the variable word else print "REDACTED" #otherwise, print the value redacted end end </code></pre> <p>The program works if I use a string separated by an space and only if I change</p> <pre><code>word = word + "" </code></pre> <p>instead of</p> <pre><code>word = word + " " </code></pre> <p>I would truly appreciate if someone break it down for me, step by step.</p> <p>I created a video of it for a more visual explanation of it. here is the link: <a href="http://screencast.com/t/X1WrZqZseG" rel="nofollow">ruby redaction video</a></p> <p>thank you.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload