printing a redacted word in an if loop

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • heiro1
    New Member
    • Jan 2013
    • 29

    printing a redacted word in an if loop

    My code won't print "REDACTED" in place of the redact variable. I do not know why though. Can anyone shed some light? I appreciate it! Here is my code :

    Code:
    puts "Whats your input brah?"
    text = gets.chomp
    puts "Whatchu are you hiding bro?"
    redact = gets.chomp
    words = text.split(" ")
    words.each {|x| if x == redact print "REDACTED"+" " else print x+" "}
    Last edited by heiro1; Apr 25 '13, 06:00 PM. Reason: I tired another approach but still experiencing the same problem
  • heiro1
    New Member
    • Jan 2013
    • 29

    #2
    This code definitely works if I use "do" instead of the curly braces. I tested it. The tutorial I am using said that those two are the same thing and can be used inter-changably but as I found, it doesn't work when I use curly brackets. Unless I am missing something important.

    Comment

    • heiro1
      New Member
      • Jan 2013
      • 29

      #3
      I found the answer already but thank you if you were about to post something helpful!

      Code:
      puts "Whats your input brah?"
      text = gets.chomp
      puts "Whatchu are you hiding bro?"
      redact = gets.chomp
      words = text.split(" ")
      words.each {|x| if x == redact then print "REDACTED"+" " else print "#{x}"+" " end}

      Comment

      Working...