Ruby | at() function Last Updated : 11 Jul, 2025 Summarize Comments Improve Suggest changes Share Like Article Like Report The at() function in Ruby is used to return the element of the specified index. Index 0 is for the first element of the array, 1 for the second element of the array and so on. The negative index counts from the end of the input array. Syntax: Array.at(Index) Here Array is the input array of elements at which at() function is called. Parameters: Index : Its corresponding elements are to be returned and this index may be negative, positive or zero. Returns: the corresponding elements whose index is taken as the parameter. Example 1: Ruby # Initialising a array of elements Array = ["a", "b", "c", "d", "e", "gfg", "Geeks", "Geek", "GeeksforGeeks"] # Calling to at() function A = Array.at(0) B = Array.at(1) C = Array.at(3) D = Array.at(5) E = Array.at(-1) F = Array.at(-3) # Getting the corresponding elements # whose indexes are given as parameter puts "#{A}" puts "#{B}" puts "#{C}" puts "#{D}" puts "#{E}" puts "#{F}" Output: a b d gfg GeeksforGeeks Geeks Example 2: Ruby # Initializing a array of elements Array = [0, 1, 2, 3, 4, 10, 20, 30, 40] # Calling the at() function with indexes # as the parameter and getting the # corresponding elements whose indexes are given puts "#{Array.at(0)}" puts "#{Array.at(1)}" puts "#{Array.at(3)}" puts "#{Array.at(5)}" puts "#{Array.at(-1)}" puts "#{Array.at(-3)}" Output: 0 1 3 10 40 20 Reference: https://devdocs.io/ruby~2.5/array#method-i-at Comment More infoAdvertise with us Next Article Ruby | Time day() function K Kanchan_Ray Follow Improve Article Tags : Ruby Ruby-Methods Similar Reads Ruby | Time day() function The day() is an inbuilt method in Ruby returns the day of the month for time. Syntax: time.day() Parameters: The function accepts no parameter Return Value: It returns the day of the month for time. Example 1: CPP # Ruby code for day() method # Include Time require 'time' # Declaring time a = Time.n 1 min read Ruby | Time day() function The day() is an inbuilt method in Ruby returns the day of the month for time. Syntax: time.day() Parameters: The function accepts no parameter Return Value: It returns the day of the month for time. Example 1: CPP # Ruby code for day() method # Include Time require 'time' # Declaring time a = Time.n 1 min read Ruby | Range each() function The each() is an inbuilt method in Ruby iterates over every element in the range. Syntax: range1.each(|el| block) Parameters: The function accepts a block which specifies the way in which the elements are iterated. Return Value: It returns every elements in the range. Example 1: Ruby # Ruby program 1 min read Ruby | Range each() function The each() is an inbuilt method in Ruby iterates over every element in the range. Syntax: range1.each(|el| block) Parameters: The function accepts a block which specifies the way in which the elements are iterated. Return Value: It returns every elements in the range. Example 1: Ruby # Ruby program 1 min read Ruby | Range to_a() function The to_a() is an inbuilt method in Ruby returns an array containing the numbers in the given range. Syntax: range1.to_a() Parameters: The function accepts no parameter. Return Value: It returns an array containing all the numbers. Example 1: Ruby # Ruby program for to_a() # method in Range # Initial 1 min read Ruby | Range to_a() function The to_a() is an inbuilt method in Ruby returns an array containing the numbers in the given range. Syntax: range1.to_a() Parameters: The function accepts no parameter. Return Value: It returns an array containing all the numbers. Example 1: Ruby # Ruby program for to_a() # method in Range # Initial 1 min read Like