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 |
chevron_right
filter_none
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 |
chevron_right
filter_none
Output:
"Ru \n y" "Ar\b\\bcles"
Recommended Posts:
- Ruby | Rational inspect() function
- Ruby | Hash inspect() function
- Ruby | BigDecimal class inspect value
- Ruby | Array class inspect() function
- Ruby | Time inspect function
- Ruby | Range inspect() function
- Ruby | Struct inspect() function
- Ruby | Regexp inspect() function
- Ruby | Symbol inspect function
- Ruby | StringScanner inspect function
- Ruby | String hex Method
- Ruby | String include? Method
- Ruby | String delete_suffix! Method
- Ruby | String dump Method
- Ruby | String each_byte Method
- Ruby | String * Method
- Ruby | String + Method
- Ruby | String << Method
- Ruby | String insert Method
- Ruby | String chomp! Method
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


