Ruby : Have you tried to enclose URLs inside ruby string with single/double quote?

I stumbled upon this when I was trying store URL in a Hash’s key to use inside a loop. The text editor (IDE) warned me and I was shocked I did I do?

# Try this in IRB
a = '\organization\12\'

# I believe you got in trouble
# You need to do like
a = '\organization\12\\'

Why is this happening?

Ruby treats \’  as if you are trying to print the singlequote char. It thinks it as a escape sequence

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s