If I do
template_string = "class=btn submit-button %<additional_classes>"
format(template_string, additional_classes: 'some-class')
it works. However, if I do
template_string = "class='btn submit-button %<additional_classes>'"
format(template_string, additional_classes: 'some-class')
it fails, giving
ArgumentError:
malformed format string - %'
(Notice the quotation marks surrounding the classes in the second template_string - this is the only difference between the two blocks of Ruby code). How do I make it work? In other words, how do I produce the following?
class='btn submit-button some-class'
I don't believe that I can just use interpolation, because sometimes I need to pass in other variables. In other words, I can't do
additional_classes = 'some-class'
"class='btn submit-button #{additional_classes}'"
because sometimes I want to reuse the same string "template" but pass in other variables, to produce strings such as the following:
class='btn submit-button some-other-class'
or
class='btn submit-button some-third-class'