Ruby | Struct each() function Last Updated : 18 Dec, 2019 Comments Improve Suggest changes Like Article Like Report 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 # 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) } Output: Geeksforgeeks India 581 Example 2: Ruby # 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) } Output: Twinkle Bajaj India 12345 Comment More infoAdvertise with us Next Article Ruby | Struct each() function G gopaldave Follow Improve Article Tags : Ruby Ruby-Methods Ruby Struct-class Similar Reads Ruby | Struct eql?() function The eql?() is an inbuilt method in Ruby returns true if other has the same struct subclass and has equal member values. Syntax: struct1.eql?(struct2) Parameters: The function accepts no parameter. Return Value: It returns boolean value true if both the given ranges are equal, else it returns false. 1 min read Ruby | Struct == function The == is an inbuilt method in Ruby returns true if other has the same struct subclass and has equal member values. Syntax: struct1 == struct2 Parameters: The function accepts no parameter. Return Value: It returns boolean value true if both the given ranges are equal, else it returns false. Example 1 min read Ruby | Struct to_a() function The to_a() is an inbuilt method in Ruby that returns an array with the value of the particular struct. Syntax: struct_name.to_a[integer] Parameters: The function accepts an integer parameter which specifies the index of the struct value to be returned. Return Value: It returns the value of struct. 1 min read Ruby | Struct filter() function The filter() is an inbuilt method in Ruby that returns an array which contains the member value from struct which returns a true value for the given block. Syntax: filter {|obj| block } Parameters: The function accepts a single parameter block which specifies the condition. Return Value: It returns 1 min read Ruby | Struct values_at() function The values_at() is an inbuilt method in Ruby that returns an array with the struct members values. Selector can be of two types: Integer or Range offset. Syntax: struct_name.values_at(range) Parameters: The function takes a single parameter range which will specify the start and end of the struct me 1 min read Like