change the output on the fly with the %s format flag and %: : Convert to String « String « Ruby






change the output on the fly with the %s format flag and %:


hi = "Hello, %s"

puts hi % "Tom!" # => "Hello, Tom!"

puts hi % "people!" # => "Hello, people!"

puts hi % "universe!" # => "Hello, universe!"

 








Related examples in the same category

1.call the to_s method on many built-in classes to return the contents of the object as a string
2.Convert an object to a string with to_s.