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:
# Ruby program for each method in struct # Include struct Company = Struct.new(:name, :address, :zip) #initialise struct ele = Company.new("Geeksforgeeks", "India", 581) # Prints the value of each member ele.each {|x| puts(x) } |
chevron_right
filter_none
Output:
Geeksforgeeks India 581
Example 2:
# Ruby program for each method in struct # Include struct Employee = Struct.new(:name, :address, :zip) #initialise struct ele = Employee.new("Twinkle Bajaj", "India", 12345) # Prints the value of each member ele.each {|x| puts(x) } |
chevron_right
filter_none
Output:
Twinkle Bajaj India 12345
Recommended Posts:
- Ruby | Struct to_s() function
- Ruby | Struct eql?() function
- Ruby | Struct values() function
- Ruby | Struct length() function
- Ruby | Struct members() function
- Ruby | Struct size() function
- Ruby | Struct to_a() function
- Ruby | Struct values_at() function
- Ruby | Struct filter() function
- Ruby | Struct == function
- Ruby | Struct inspect() function
- Ruby | Struct Class
- Ruby | Hash each() function
- Ruby | Enumerator each function
- Ruby | Range each() function
- Ruby | Array class each() operation
- Ruby | Matrix cofactor() function
- Ruby Integer odd? function with example
- Ruby Integer div() function with example
- Ruby | Symbol to_s function
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

