OneBite.Dev - Coding blog in a bite size

format a string in Ruby

Code snippet on how to format a string in Ruby

  name = "John Doe"
  puts "Hello #{name}!"

This code takes a variable called name, which is set to the string “John Doe”. Then, it uses string interpolation to print a statement. puts is a built-in Ruby method that prints a string, and #{name} inserts the variable name into the string. The final output after the code is run is “Hello John Doe!”

ruby