Open In App
Related Articles

Ruby | String dump Method

Improve
Improve
Improve
Like Article
Like
Save Article
Save
Report issue
Report
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:
# Ruby program to demonstrate 
# the dump method 
       
# Taking a string and 
# using the method
str = "ruby \n ''".dump
  
puts str.dump

                    
Output:
"\"ruby \\n ''\""
Example 2:
# Ruby program to demonstrate 
# the dump method 
       
# Taking a string and 
# using the method
str = "yumy \n\n\n ''".dump
  
puts str.dump

                    
Output:
"\"yumy \\n\\n\\n ''\""

Last Updated : 13 Dec, 2019
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads