Forum: Ruby backslash in quotes

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
itsme213 (Guest)
on 2006-03-11 07:55
(Received via mailing list)
Why is \ the same as \\ in the 1st 2 cases, but not in the 3rd?

irb(main):001:0> 'c:\a\b'
=> "c:\\a\\b"
irb(main):002:0> 'c:\a\\b'
=> "c:\\a\\b"
irb(main):004:0> 'c:\a\b\'
irb(main):005:0'

Thanks.
Alan B. (Guest)
on 2006-03-11 08:53
itsme213 wrote:
> Why is \ the same as \\ in the 1st 2 cases, but not in the 3rd?
>
> irb(main):001:0> 'c:\a\b'
> => "c:\\a\\b"
> irb(main):002:0> 'c:\a\\b'
> => "c:\\a\\b"
> irb(main):004:0> 'c:\a\b\'
> irb(main):005:0'
>
> Thanks.

I'm new here, but I can answer this one.  In the last one you are
escaping your single ' mark and so are not terminating the string.  Do
you mean 'c:\a\b\\' or do you want 'c:\a\b\'' ?  To ruby it looks like
you want to embed a \n in the string and adding another ' and <cr> will
complete it.
Alan
This topic is locked and can not be replied to.