# Rubocop issues with string formating
# Examples will print key/value pairs to console with padding for key
# => "name : value goes here"
# Cop success:
puts format('%-20<key>s : %<value>s', key: 'name', value: name)
# Cop failure: Style/FormatString: Favor format over String#%
puts '%-20s : %s' % ['name', name]
# Cop failure: Style/FormatStringToken: Prefer annotated tokens (like %<foo>s) over unannotated tokens (like %s)
puts format('%-20s : %s', 'name', name)
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
name1 = "John"
name2 = "Mary"
"hello, #{name1}. Where is #{name2}?"