S
subbu
I encountered a rather peculiar behavior of strings today.
Here is my irb session:
-------------------------------------------------------------------
irb(main):001:0> 'ab\c'
irb(main):002:0' '
SyntaxError: compile error
(irb):2: unterminated string meets end of file
from (irb):2
irb(main):003:0> 'ab\\c'
=> "ab\\c"
irb(main):004:0> 'a\b'
=> "a\\b"
irb(main):005:0>
-------------------------------------------------------------------
As you can see when I typed 'ab\c' my irb didn't return. It was
expecting some thing more. Then I typed a single quote ( ' ) to
terminate the string and it gave me this SyntaxError. The same thing
happens even I type 'ab\\c'
I was trying this after reading section 3.2.1.1 of "The Ruby
Programming Language". This is what it says about backslashes in
single quoted strings:
"In single-quoted strings, a backslash is not special if the character
that follows it is anything other than a quote or a backslash. "
But at the same time if I type 'a\b' it returns 'a\\b' which is inline
with the book. Any ideas what's happening here?
Thanks
subbu
Here is my irb session:
-------------------------------------------------------------------
irb(main):001:0> 'ab\c'
irb(main):002:0' '
SyntaxError: compile error
(irb):2: unterminated string meets end of file
from (irb):2
irb(main):003:0> 'ab\\c'
=> "ab\\c"
irb(main):004:0> 'a\b'
=> "a\\b"
irb(main):005:0>
-------------------------------------------------------------------
As you can see when I typed 'ab\c' my irb didn't return. It was
expecting some thing more. Then I typed a single quote ( ' ) to
terminate the string and it gave me this SyntaxError. The same thing
happens even I type 'ab\\c'
I was trying this after reading section 3.2.1.1 of "The Ruby
Programming Language". This is what it says about backslashes in
single quoted strings:
"In single-quoted strings, a backslash is not special if the character
that follows it is anything other than a quote or a backslash. "
But at the same time if I type 'a\b' it returns 'a\\b' which is inline
with the book. Any ideas what's happening here?
Thanks
subbu