Posted about 5 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>"

By refactoring problematic code and creating automated tests, makandra can vastly improve the maintainability of your Rails application.

Owner of this card:

Avatar
Henning Koch
Last edit:
about 5 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