Open In App
Related Articles

Ruby | String inspect Method

Improve
Improve
Improve
Like Article
Like
Save Article
Save
Report issue
Report
inspect is a String class method in Ruby which is used to return a printable version of the given string, surrounded by quote marks, with special characters escaped.
Syntax: str.inspect Parameters: Returns: Here, str is the given string.
Example 1:
# Ruby program to demonstrate 
# the inspect method 
       
# Taking a string and 
# using the method
puts "Sample".inspect
puts "Articles".inspect

                    
Output:
"Sample"
"Articles"
Example 2:
# Ruby program to demonstrate 
# the inspect method 
       
# Taking a string and 
# using the method
puts "Ru \n y".inspect
puts "Ar\b\\bcles".inspect

                    
Output:
"Ru \n y"
"Ar\b\\bcles"

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