1

I can't strongly formulate what I need now, but the idea is this:

User inputs some string that looks like a template

'Welcome to #{country}!' # or 'Welcome to %%country%%!', it's not essential

Is there some gem (or may be standard tool like Erb), that could do 2 things:

  1. Validate given string (i.e. if I allow to pass only country as parameter, strings with another parameters will not be valid)

  2. Interpolate given string with passed parameters (i.e. some_method('Welcome to #{country}!', country: 'Russia')) # => 'Welcome to Russia!')

1 Answer 1

9
"Welcome to %{country}!" % {country: "Russia"}
# => "Welcome to Russia!"

"Welcome to %{country}!" % {person: "John"}
# => KeyError: key{country} not found
Sign up to request clarification or add additional context in comments.

1 Comment

I have never seen such code :). interesting one. what that % is called?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.