I have an array of values and I would like to print it in some format. In C# I would do
string.Format(" {0} | {1} _ {2}!", array[0], array[1], array[2]);
resulting in an output such as
" 10 | 20 _ 30!"
How to achieve this in Ruby?
Is this what you are looking for using String#% ?
array=[11,13,14]
" %s | %s _ %s!" % [array[0],array[1],array[2]]
# => " 11 | 13 _ 14!"
array=[0,13,14]
" %s | %s _ %s!" % array
# => " 0 | 13 _ 14!"
[*array] is redundant. It unpacks the array into... another array. Just do % array