# String#dump and quotes

**URL:** <https://www.ruby-forum.com/t/string-dump-and-quotes/50511>\
**Category:** Ruby\
**Created:** [December 17, 2005, 7:38am UTC](https://www.ruby-forum.com/t/string-dump-and-quotes/50511 "2005-12-17T07:38:41Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![danielb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/c57346/32.png) [@danielb](https://www.ruby-forum.com/u/danielb)\
**Post date:** [December 17, 2005, 7:38am UTC](https://www.ruby-forum.com/t/string-dump-and-quotes/50511/1 "2005-12-17T07:38:41Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![danielb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/c57346/32.png) [@danielb](https://www.ruby-forum.com/u/danielb)\
**Post date:** [December 17, 2005, 7:44am UTC](https://www.ruby-forum.com/t/string-dump-and-quotes/50511/2 "2005-12-17T07:44:41Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![danielb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/c57346/32.png) [@danielb](https://www.ruby-forum.com/u/danielb)\
**Post date:** [December 17, 2005, 7:47am UTC](https://www.ruby-forum.com/t/string-dump-and-quotes/50511/3 "2005-12-17T07:47:42Z")

</div>

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

On 2005.12.17 15:37, “Daniel B.” [removed\_email\_address@domain.invalid](mailto: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-----

---

<div class="post-metadata">

**Author:** ![danielb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/c57346/32.png) [@danielb](https://www.ruby-forum.com/u/danielb)\
**Post date:** [December 17, 2005, 4:18pm UTC](https://www.ruby-forum.com/t/string-dump-and-quotes/50511/4 "2005-12-17T16:18:27Z")

</div>

Ross B. wrote:

> On Sat, 17 Dec 2005 06:42:18 -0000, Hal F.  
> [removed\_email\_address@domain.invalid](mailto: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

---

<div class="post-metadata">

**Author:** ![danielb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/c57346/32.png) [@danielb](https://www.ruby-forum.com/u/danielb)\
**Post date:** [December 17, 2005, 1:54pm UTC](https://www.ruby-forum.com/t/string-dump-and-quotes/50511/5 "2005-12-17T13:54:01Z")

</div>

On Sat, 17 Dec 2005 06:42:18 -0000, Hal F.  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> 

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