+ 4

Why use #{} if we just use puts and write he is 42 years old

26th May 2017, 3:30 PM
Shaswat Singh
Shaswat Singh - avatar
2 Respuestas
+ 1
#{} allows you to personnalize your output but you can write puts "he is 42 years old" then everybody are 42 and is a man. an example: name = gets.chomp puts "How old are you, #{name} ? age = gets.chomp puts "#{name}, you are #{age} years old. Welcome"
26th May 2017, 5:33 PM
MBZH31
MBZH31 - avatar
0
So ruby won’t think 42 is a value and think it’s a variable.
3rd Nov 2019, 2:23 PM
Joshua