Print command - i need some explaination about it


#1

the example

puts "text to search"
text=gets.chomp
puts "text to redact"
redact=gets.chomp
words=text.split("")
words.each do |w|
print w+""
end

the thing that i don't understand is the print command that print ""
why we print like this (print w+"") instead of (print w)?
also what's the different between ( print w ) & ( print "#{w}" )?
i really hope some expert clear this to me


11 Iterating Over Arrays
#2

@a7lamlover
Not really an expert about Ruby (in fact, currently taking this course) but I hope I'll help you a bit!:wink:

First of all, we are doing a loop using each method which is going to print each word in text with a space (that's why we use w+" ")separating each word using concatenation. In fact, w is like a variable that we add to a string. So, if we print print w, it will print every word stuck together.
Second of all, print w is different of print "#{w}" because in the first method, we print the variable and on the second, we print the variable inside of a string. Why the second method is more useful is that you can put text with the variable in a string instead of using concatenation like this:

print "Some text with a #{variable} inside of it!"

#3

thank you soooooooo much
you cleared this for me...i feel content & refreshed now
it's was really bugging me since i started the course

thank you again for your help