Tuesday, June 28, 2016

Escaping Ruby Strings

The Rules

1. If possible, use single quotes (')

2. If you have a single line that needs interpolation, without inline double quotes, do the following:

"#{name} says, 'Hey!'"

3. If you have multiple lines use %[ <MUILTI_LINE_INTERPOLATION> ]


Note that %[ ] handles interpolation.

Example


name = 'Bob'

msg = %[#{name} says, "Hey!
What's up?"]

>> puts msg
Bob says: "Hey!
What's up?"


References

Don't escape in Strings





This work is licensed under the Creative Commons Attribution 3.0 Unported License.

1 comment:


  1. Usually I do not read post on blogs, but I would like to say that this write-up very forced me to try and do it! Your writing style has been surprised me. Great work admin..Keep update more blog..

    Linux Training in Chennai Velachery

    ReplyDelete