Ruby | Struct to_s() function
Last Updated :
06 Jan, 2020
The to_s() is an inbuilt method in Ruby that returns a string with the value of the particular struct.
Syntax: struct_name.to_s()
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.to_s
|
Output:
struct name="labrador", speciality="bark", found_in="Newfoundland"
Example 2:
animals = Struct. new ( :name )
detail = animals. new ( "golden retriever" )
puts detail.to_s
|
Output:
struct name="golden retriever"
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...