Forum: Ruby String#dump and 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.
Aee77dba395ece0a04c688b05b07cd63?d=identicon&s=25 Daniel Berger (Guest)
on 2005-12-17 07:38
(Received via mailing list)
Just out of curiosity, why are double quotes added to the start and end
of the string when doing String#dump?  I can see where it's happening
in string.c, but I don't understand the purpose.

Thanks,

Dan
C1bcb559f87f356698cfad9f6d630235?d=identicon&s=25 Hal Fulton (Guest)
on 2005-12-17 07:44
(Received via mailing list)
Daniel Berger wrote:
> Just out of curiosity, why are double quotes added to the start and end
> of the string when doing String#dump?  I can see where it's happening
> in string.c, but I don't understand the purpose.

I think it's just for looks, to emphasize that it's a string.
Like String#inspect.

FWIW, I think if you eval a dump, you get the original string back.
I *think* that's correct. But it may be just a side effect.


Hal
5c7bdd14d6885c8275eaf78be41d120a?d=identicon&s=25 Eero Saynatkari (Guest)
on 2005-12-17 07:47
(Received via mailing list)
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 2005.12.17 15:37, "Daniel Berger" <djberg96@gmail.com> wrote:
> Just out of curiosity, why are double quotes added to the start and end
> of the string when doing String#dump?  I can see where it's happening
> in string.c, but I don't understand the purpose.

I venture as my guess that it is merely intended to allow
storing an 'internal' representation of the String. It looks
like all special characters are escaped. This might be useful
for, say, #eval or debugging maybe?

  'foo'.dump  # => "\"foo\""
  "\nf".dump  # => "\"\\nf\""

> Thanks,
>
> Dan


E
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (GNU/Linux)

iD8DBQFDo70LxvA1l6h+MUMRAlgSAJ9Q7G+i7OrUtmm1P1eE67mbBzHmSQCgibwd
fJ7fffK1TP1SXfIBuaPyvc4=
=dM1n
-----END PGP SIGNATURE-----
82e62c756d89bc6fa0a0a2d7f2b1e617?d=identicon&s=25 Ross Bamford (Guest)
on 2005-12-17 13:54
(Received via mailing list)
On Sat, 17 Dec 2005 06:42:18 -0000, Hal Fulton
<hal9000@hypermetrics.com>
wrote:

>
I assumed that _was_ the point of the quotes and the escaping it does ?
C1bcb559f87f356698cfad9f6d630235?d=identicon&s=25 Hal Fulton (Guest)
on 2005-12-17 16:18
(Received via mailing list)
Ross Bamford wrote:
> On Sat, 17 Dec 2005 06:42:18 -0000, Hal Fulton
> <hal9000@hypermetrics.com>  wrote:
>>
>> FWIW, I think if you eval a dump, you get the original string back.
>> I *think* that's correct. But it may be just a side effect.
>>
>
> I assumed that _was_ the point of the quotes and the escaping it does ?
>

It may well be. I've just never seen that documented.

I've rarely used dump anyway.


Hal
This topic is locked and can not be replied to.