I am just starting to learn Ruby (first time programming), and have a basic syntactical question with regards to variables, and various ways of writing code.
Chris Pine's "Learn to Program" taught me to write a basic program like this...
num_cars_again= 2
puts 'I own ' + num_cars_again.to_s + ' cars.'
This is fine, but then I stumbled across the tutorial on ruby.learncodethehardway.com, and was taught to write the same exact program like this...
num_cars= 2
puts "I own #{num_cars} cars."
They both output the same thing, but obviously option 2 is a much shorter way to do it.
Is there any particular reason why I should use one format over the other?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…