[quoted from http://c2.com/cgi/wiki?IwannaLearnRuby]
What is String.dump method for? Where can I look for a usage example?
Brgds,
Alex
[quoted from http://c2.com/cgi/wiki?IwannaLearnRuby]
What is String.dump method for? Where can I look for a usage example?
Brgds,
Alex
Alexey Verhovsky wrote:
What is String.dump method for? Where can I look for a usage example?
See the “Reflection, ObjectSpace and Distributed Ruby” chapter of
“Programming Ruby”:
http://www.ruby-doc.org/docs/ProgrammingRuby/html/ospace.html
The section of interest is titled “Marshaling and Distributed Ruby”.
Hope this helps,
Lyle
(flori@lambda:flori/ 0)$ ri String#dump
------------------------------------------------------------ String#dump
str.dump => new_str
On Sun, 2004-03-28 at 23:23, =?koi8-r?Q?=22?=Alexey Verhovsky=?koi8-r?Q?=22=20?= wrote:
[quoted from http://c2.com/cgi/wiki?IwannaLearnRuby]
What is String.dump method for? Where can I look for a usage example?
Produces a version of _str_ with all nonprinting characters
replaced by +\nnn+ notation and all special characters escaped.
–
="puts’=‘+.inspect+‘;’+";puts’='+.inspect+‘;’+_
Given that I can rewrite your “usage example” like this:
="puts’=’+.dump+’;’+";puts’=’+.dump+’;’+_
, String#dump must be the same thing as String#inspect, and has nothing to do with marshalling. Correct?
I would still appreciate some reallife usage. I can vaguely imagine using it to insert any given string into a regexp or as an argument to a generated Ruby script. Is that the purpose, or something else?
Quoteing alex_verk@mail.ru, on Mon, Mar 29, 2004 at 07:02:08AM +0900:
Given that I can rewrite your “usage example” like this:
="puts’=‘+.dump+‘;’+";puts’='+.dump+‘;’+_
, String#dump must be the same thing as String#inspect, and has nothing to do with marshalling. Correct?
I would still appreciate some reallife usage. I can vaguely imagine
using it to insert any given string into a regexp or as an argument to
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
a generated Ruby script. Is that the purpose, or something else?
Yes, that is one important use, though you could use it for other things.
Sam
Given that I can rewrite your “usage example” like this:
="puts’=‘+.dump+‘;’+";puts’='+.dump+‘;’+_
, String#dump must be the same thing as String#inspect,
and has nothing to do with marshalling. Correct?
It’s not the same method as inspect, but similar. There is also
a Marshal.dump method, but String#dump has nothing to do with such
militaristic endeavours.
I would still appreciate some reallife usage.
One good use of dump is for debugging of network streams. If you
ouput arbitrary binary data on your terminal strange things
can happen, so it’s better to escape the dangerous characters
before doing that.
On Mon, 2004-03-29 at 00:02, =?koi8-r?Q?=22?=Alexey Verhovsky=?koi8-r?Q?=22=20?= wrote: