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:
# 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 ''\""
Contact Us