I am working on replacing environment variables with values in Ruby, and I’m trying to figure out the best way to do this. I have a JSON feed that I am parsing, which looks like this: %MY_SERVER/json/data/mydata?someparameter and another that looks like %MY_OTHER_SERVER/json/data/mydata?somethingdifferent=thisorthat
Each of the servers has a different URL that needs to be input. I have looked around and have seen things talking about using replace or looking for a specific pattern, but I don’t think that is the most effective way.
Can anyone point me in the right direction, or offer some advice on the best way to accomplish my task?
Here’s the dynamic approach you seek:
You just need to scan your input string and find all things that look like a placeholder. Luckily, your strings have them clearly formatted. Then you just supply values in your
ENV. If a value for placeholder is missing, it won’t be replaced.