Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

sprintf and %

name = "Foo"
number = 42

text = "The name is %s" % name
puts text

text = "The name is %s the number is %s" % {name, number} # Tuple
puts text

text = "The name is %s the number is %s" % [name, number] # Array
puts text

text = "The name is %{txt} the number is %{num}" % {txt: name, num: number} # NamedTuple
puts text

text = sprintf "The name is %s the number is %s", name, number
puts text
The name is Foo
The name is Foo the number is 42
The name is Foo the number is 42
The name is Foo the number is 42
The name is Foo the number is 42