Posted over 4 years ago. Visible to the public. Linked content.

Defining Ruby strings with % (percent) notation

The attached post shows some alternative ways to define Strings in Ruby using the percent notation. This can be useful when you'd like to use quotes (") or single-quotes (') in your strings:

Copy
%(any alpha-numeric) %[char can be] %%used as% %!delimiter\!! # escape '!' literal %( (pa(re(nt)he)sis) ) #=> "(pa(re(nt)he)sis)" %[ [square bracket] ] #=> "[square bracket]" %{ {curly bracket} } #=> "{curly bracket}" %< <pointy bracket> > #=> "<pointy bracket>" %< \<this works as well\> > #=> "<this works as well>"

Once an application no longer requires constant development, it needs periodic maintenance for stable and secure operation. makandra offers monthly maintenance contracts that let you focus on your business while we make sure the lights stay on.

Owner of this card:

Avatar
Henning Koch
Last edit:
over 4 years ago
About this deck:
We are makandra and do test-driven, agile Ruby on Rails software development.
License for source code
Posted by Henning Koch to makandra dev
This website uses cookies to improve usability and analyze traffic.
Accept or learn more