str = "Hi %{name},%{msg}. Bye %{name}." #yaml it,de-yaml it back to string h = {:name=> "John",:msg=> "this message is for you"} puts str % h #=>Hi John,This message is for you. Bye John.