We store configuration strings in YAML files. It’s common that we need to substitute part of the string with runtime values. Hence we introduce some kind of placeholders in the config strings. Given an example that our application may need to hit an external URL to retrieve some remote resources at runtime. To do this, we could make a config string in our application’s config YAML file like this
Then in our code, we substitute “RESOURCE1” and “RESOURCE2” with the real resource names we require. In my early days of programming in Ruby, I used some very ordinary string substitution method like this
It works, but I don’t really like it… So I found something better, that is to use Ruby’s string interpolation methods
A lot nicer, but still can be better. Thanks to a colleague of mine, Aleksey Gureiev, another more elegant way can be used
That is satisfactory!