469,327 Members | 1,295 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,327 developers. It's quick & easy.

printing a redacted word in an if loop

heiro1
29
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 :

Expand|Select|Wrap|Line Numbers
  1. puts "Whats your input brah?"
  2. text = gets.chomp
  3. puts "Whatchu are you hiding bro?"
  4. redact = gets.chomp
  5. words = text.split(" ")
  6. words.each {|x| if x == redact print "REDACTED"+" " else print x+" "}
Apr 25 '13 #1
2 5821
heiro1
29
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.
Apr 25 '13 #2
heiro1
29
I found the answer already but thank you if you were about to post something helpful!

Expand|Select|Wrap|Line Numbers
  1. puts "Whats your input brah?"
  2. text = gets.chomp
  3. puts "Whatchu are you hiding bro?"
  4. redact = gets.chomp
  5. words = text.split(" ")
  6. words.each {|x| if x == redact then print "REDACTED"+" " else print "#{x}"+" " end}
Apr 25 '13 #3

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

reply views Thread by Andy Newland | last post: by
4 posts views Thread by Jeff Harbin | last post: by
5 posts views Thread by Stefania Scott | last post: by
5 posts views Thread by CJ Taylor | last post: by
9 posts views Thread by ewolfman | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by suresh191 | last post: by
reply views Thread by Purva khokhar | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.