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:
animals = Struct. new ( :name , :speciality , :found_in )
detail = animals. new ( "labrador" , "bark" , "Newfoundland" )
puts detail.inspect
|
Output:
struct name="labrador", speciality="bark", found_in="Newfoundland"
Example 2:
animals = Struct. new ( :name )
detail = animals. new ( "golden retriever" )
puts detail.inspect
|
Output:
struct name="golden retriever"