Skip to content
Related Articles

Related Articles

Ruby | String dump Method

Improve Article
Save Article
  • Last Updated : 13 Dec, 2019
Improve Article
Save Article

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 ''\""
My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!