Ruby | Struct inspect() function
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 structanimals = Struct.new(:name, :speciality , :found_in) # initialize valuesdetail = animals.new("labrador", "bark" , "Newfoundland") # inspect usedputs detail.inspect |
Output:
struct name="labrador", speciality="bark", found_in="Newfoundland"
Example 2:
# Ruby program for inspect method in struct # Include structanimals = Struct.new(:name) # initialize valuesdetail = animals.new("golden retriever") # inspect usedputs detail.inspect |
Output:
struct name="golden retriever"
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.



