String#dump and quotes


#1

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


#2

Daniel B. 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


#3

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 2005.12.17 15:37, “Daniel B.” removed_email_address@domain.invalid 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-----


#4

Ross B. wrote:

On Sat, 17 Dec 2005 06:42:18 -0000, Hal F.
removed_email_address@domain.invalid 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


#5

On Sat, 17 Dec 2005 06:42:18 -0000, Hal F.
removed_email_address@domain.invalid
wrote:

I assumed that was the point of the quotes and the escaping it does ?