Ruby | Struct values_at() function Last Updated : 19 Mar, 2024 Comments Improve Suggest changes Like Article Like Report 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 members. Return Value: It returns the array with member values. Example 1: Ruby # Ruby program for values_at method in struct # Include struct Student = Struct.new(:name, :address) #initialize values detail = Student.new("Raman", "Kolkata") # values_at used puts detail.values_at(0, 1) Output: Raman Kolkata Example 2: Ruby # Ruby program for values_at method in struct # Include struct animals = Struct.new(:name, :speciality , :found_in) # initialize values detail = animals.new("labrador", "bark" , "Newfoundland") # values_at used puts detail.values_at(1,2) Output: bark Newfoundland Comment More infoAdvertise with us Next Article Ruby | Struct values_at() function G gopaldave Follow Improve Article Tags : Ruby Ruby-Methods Ruby Struct-class Similar Reads Ruby | Struct values() function The values() 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 struct value to be returned. Return Value: It returns the value of struct. Example 1: R 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 each() function 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 retu 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 | Array values_at() function Array#values_at() : values_at() is a Array class method which returns an array containing the elements in self corresponding to the given selector. Syntax: Array.values_at() Parameter: Array Return: an array containing the elements in self corresponding to the given selector Example #1 : Ruby # Ruby 1 min read Like