The inspect() is an inbuilt method in Ruby that returns a string with the value of the particular struct.
Syntax: struct_name.inspect()
Parameters: The function does not accepts any parameter.
Return Value: It returns the value of struct.
Example 1:
# Ruby program for inspect method in struct # Include struct animals = Struct.new(:name, :speciality , :found_in) # initialize values detail = animals.new("labrador", "bark" , "Newfoundland") # inspect used puts detail.inspect |
chevron_right
filter_none
Output:
struct name="labrador", speciality="bark", found_in="Newfoundland"
Example 2:
# Ruby program for inspect method in struct # Include struct animals = Struct.new(:name) # initialize values detail = animals.new("golden retriever") # inspect used puts detail.inspect |
chevron_right
filter_none
Output:
struct name="golden retriever"
Recommended Posts:
- Ruby | StringScanner inspect function
- Ruby | Regexp inspect() function
- Ruby | Rational inspect() function
- Ruby | Time inspect function
- Ruby | Symbol inspect function
- Ruby | Hash inspect() function
- Ruby | Range inspect() function
- Ruby | Array class inspect() function
- Ruby | Struct eql?() function
- Ruby | Struct == function
- Ruby | Struct each() function
- Ruby | Struct values_at() function
- Ruby | Struct filter() function
- Ruby | Struct to_a() function
- Ruby | Struct to_s() function
- Ruby | Struct members() function
- Ruby | Struct size() function
- Ruby | Struct length() function
- Ruby | Struct values() function
- Ruby | BigDecimal class inspect value
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.

