Ruby | Range cover?() function Last Updated : 12 Jul, 2025 Comments Improve Suggest changes Like Article Like Report 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 returns a boolean value true if the given object lies within the given range, else it returns false. Example 1: Ruby # Ruby program for cover? method in Range # Initialize range range1 = (0..10) # Prints if lies or not puts range1.cover?(6) puts range1.cov</div>er?(13) Output: true false Example 2: Ruby # Ruby program for cover? method in Range # Initialize range range1 = (0..5) # Prints if lies or not puts range1.cover?((8)) puts range1.cover?((18)) Output: false false Comment More infoAdvertise with us Next Article Ruby | Range end() function G gopaldave Follow Improve Article Tags : Ruby Ruby-Methods Ruby Range-class Similar Reads 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 end() function 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 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 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 first() function The first() is an inbuilt method in Ruby returns an array of first X elements. If X is not mentioned, it returns the first element only. Syntax: range1.first(X) Parameters: The function accepts X which is the number of elements from the beginning. Return Value: It returns an array of first X element 1 min read Like