Ruby | Range include?() function Last Updated : 19 Mar, 2024 Comments Improve Suggest changes Like Article Like Report The include?() is an inbuilt method in Ruby returns a boolean value true if the given object lies within the given range, else it returns false. Syntax: range1.include?(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 include? method in Range # Initialize range range1 = (0..10) # Prints if lies or not puts range1.include?(6) puts range1.include?(13) Output: true false Example 2: Ruby # Ruby program for include? method in Range # Initialize range range1 = (2..5) # Prints if lies or not puts range1.include?(7) puts range1.include?(11) Output: false false Comment More infoAdvertise with us Next Article Ruby | Range include?() function gopaldave Follow Improve Article Tags : Ruby Ruby-Methods Ruby Range-class Similar Reads Ruby | Range inspect() function The inspect() is an inbuilt method in Ruby returns the range object in a printable form Syntax: range1.inspect() Parameters: The function accepts no parameter Return Value: It returns the range object in a printable form Example 1: Ruby # Ruby program for inspect() # method in Range # Initialize ran 1 min read Ruby | Range last() function The last() is an inbuilt method in Ruby returns an array of last X elements. If X is not mentioned, it returns the last element only. Syntax: range1.last(X) Parameters: The function accepts X which is the number of elements from the end. Return Value: It returns an array of last X elements. Example 1 min read Ruby | Set include?() function The include?() is an inbuilt method in Ruby returns true if the set contains the given object. It returns false if it does not contains the given object. Syntax: s1_name.include?(object) Parameters: The function accepts a mandatory parameter object whose presence is to be checked for. Return Value: 1 min read Ruby | Hash include?() function Hash#include?() is a Hash class method which checks whether the given key is present in hash. Syntax: Hash.include?() Parameter: Hash values Return: true - if given key"" is present in hash otherwise return false Example #1 : Ruby # Ruby code for Hash.has_value?() method # declaring Hash value a = { 2 min read Ruby | Range member? function The member?() is an inbuilt method in Ruby returns a boolean value true if the given object lies within the given range, else it returns false. Syntax: range1.member?(obj) Parameters: The function accepts an object which is to be checked for. Return Value: It returns a boolean value true if the give 1 min read Ruby | Range hash() function The hash() is an inbuilt method in Ruby returns a hash-code for the given range. The hash-value will vary for every execution. Syntax: range1.hash() Parameters: The function accepts no parameter. Return Value: It returns a hash-code for the given range. Example 1: Ruby # Ruby program for hash() # me 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 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 size() function The size() is an inbuilt method in Ruby returns the size of the range. It returns the number of elements in the range. Syntax: range1.size() Parameters: The function accepts no parameter. Return Value: It returns the number of elements in the range. Example 1: Ruby # Ruby program for size() # method 1 min read Like