Ruby | Struct each() function
Last Updated :
18 Dec, 2019
The each() is an inbuilt method in Ruby returns every value of the struct in the existing order. In case no block is passed, it returns an enumerator.
Syntax: struct_name.each{|x| block }
Parameters: The function accepts a single parameter block which is the way it is iterated.
Return Value: It returns each struct member in its respective order.
Example 1:
Company = Struct. new ( :name , :address , :zip )
ele = Company. new ( "Geeksforgeeks" , "India" , 581 )
ele. each {|x| puts(x) }
|
Output:
Geeksforgeeks
India
581
Example 2:
Employee = Struct. new ( :name , :address , :zip )
ele = Employee. new ( "Twinkle Bajaj" , "India" , 12345 )
ele. each {|x| puts(x) }
|
Output:
Twinkle Bajaj
India
12345
Share your thoughts in the comments
Please Login to comment...