How to use ":template"-type strings in ruby?

Viewed 1970

Both rails routes and whenever and a few other things I can't remember have a user-specified template string like so:

template_str = "I am going to :place at :time"

And then there's some magic function which embeds data in place of :place and :time, like so:

template_str.magic_embed_function(place: 'bed', time: '10 pm') 
#=> "I am going to bed at 10 pm"

How can I do this in my ruby projects? Is there a gem that implements String#magic_embed_function?

2 Answers
Related