Open In App

Ruby | Struct inspect() function

Last Updated : 18 Dec, 2019
Improve
Improve
Like Article
Like
Save
Share
Report

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 


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


Output:

struct name="golden retriever"

Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads