Skip to content

End of Life Ruby 3.0 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →

instance method

String#dump

str.dump → new_str

Returns a quoted version of the string with all non-printing characters replaced by \xHH notation and all special characters escaped.

This method can be used for round-trip: if the resulting new_str is eval’ed, it will produce the original string.

Example
"hello \n ''".dump     #=> "\"hello \\n ''\""
"\f\x00\xff\\\"".dump  #=> "\"\\f\\x00\\xFF\\\\\\\"\""

See also String#undump.

Ruby version changes

  1. 3.0
See also #downcase! #each_byte #downcase #each_char also in 4.1 · 4.0 · 3.4 · 3.3 · 3.2 · 3.1