472,146 Members | 1,261 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,146 software developers and data experts.

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 5889
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
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.