Ruby | Range end() function Last Updated : 12 Jul, 2025 Summarize Comments Improve Suggest changes Share Like Article Like Report The end() is an inbuilt method in Ruby returns the last element of the given range. Syntax: range1.end() Parameters: The function accepts no parameter Return Value: It returns the last element of the given range. Example 1: Ruby # Ruby program for end() method in Range # Initialize range range1 = (0..10) # Prints the last element puts range1.end() Output: 10 Example 2: Ruby # Ruby program for end() method in Range # Initialize range range1 = (10..20) # Prints the last element puts range1.end() Output: 20 Comment More infoAdvertise with us Next Article Ruby | Range each() function G gopaldave Follow Improve Article Tags : Ruby Ruby-Methods Ruby Range-class Similar Reads Ruby | Range begin() function The begin() is an inbuilt method in Ruby returns the first element of the given range. Syntax: range1.begin() Parameters: The function accepts no parameter Return Value: It returns the first element of the given range. Example 1: Ruby # Ruby program for begin() method in Range # Initialize range ran 1 min read Ruby | Range eql?() function The eql?() is an inbuilt method in Ruby returns boolean value true if both the given ranges are equal, else it returns false. Syntax: range1.eql?(range2) Parameters: The function accepts no parameter Return Value: It returns boolean value true if both the given ranges are equal, else it returns fals 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 entries() function The entries() is an inbuilt method in Ruby returns an array containing all elements of the given range. Syntax: range1.entries() Parameters: The function accepts no parameter. Return Value: It returns an array containing all elements of the given range. Example 1: Ruby # Ruby program for entries() # 1 min read Ruby | Range cover?() function The cover?() is an inbuilt method in Ruby returns a boolean value true if the given object lies within the given range, else it returns false. The object can be an element or a range. Syntax: range1.cover?(obj) Parameters: The function accepts an object which is to be checked for. Return Value: It r 1 min read Ruby | Range exclude_end? function The exclude_end?() is an inbuilt method in Ruby returns boolean value true if the range excludes its end value, else it returns false. Syntax: range1.exclude_end? Parameters: The function accepts no parameter Return Value: It returns boolean value true if the range excludes its end value, else it re 1 min read Like