How to create a string template: "some string {some_stub_var}"?

Viewed 1797

I want to create with a stub-template in it:

  my_str_template = "some string {some_stub_var}"
  # note that there's no variable "some_stub_var" in the current scope

So that sometime later in my application I'm able to do something like this:

my_str = my_str_template.format(some_stub_var: "my_real_string_var_123")

1) How to do that?

2) What's it called?

3 Answers

You can use EEx

EEx.eval_string("foo <%= bar %>", bar: "baz")
Related