Formatação da string rubi
name1 = "John"
name2 = "Mary"
"hello, #{name1}. Where is #{name2}?"
Anas Mahasin Nabih
name1 = "John"
name2 = "Mary"
"hello, #{name1}. Where is #{name2}?"
time = 5
message = "Processing of the data has finished in %d seconds" % [time]
puts message
Output => "Processing of the data has finished in 5 seconds"
score = 78.5431
puts "The average is %0.2f" % [score]
Output => The average is 78.54
puts "122 in HEX is %x" % [122]
Output => 122 in HEX is 7a
puts "The number is %04d" % [20]
Output => The number is 0020
names_with_ages = [["john", 20], ["peter", 30], ["david", 40], ["angel", 24]]
names_with_ages.each { |name, age| puts name.ljust(10) + age.to_s }
# Prints the following table
john 20
david 30
peter 40
angel 24