Ruby | String dump Method
dump is a String class method in Ruby which is used to generate a version of the given string with all non-printing characters replaced by \nnn notation and all special characters escaped.
Syntax: str.dump
Parameters: Here, str is the given string.
Returns: A new string with all non-printing characters replaced by \nnn notation and all special characters escaped.
Example 1:
str = "ruby \n ''" .dump
puts str.dump
|
Output:
"\"ruby \\n ''\""
Example 2:
str = "yumy \n\n\n ''" .dump
puts str.dump
|
Output:
"\"yumy \\n\\n\\n ''\""
Last Updated :
13 Dec, 2019
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...