Ruby | Range new() function Last Updated : 19 Mar, 2024 Comments Improve Suggest changes Like Article Like Report The new() is an inbuilt method in Ruby returns a new range of numbers. Syntax: range1.new(first, last) Parameters: The function accepts first and last which is the range that is to be created. Return Value: It returns the range of numbers. Example 1: Ruby # Ruby program for new() # method in Range # Initialize range range1 = Range.new(8, 12) # Prints the range puts range1 Output: 8..12 Example 2: Ruby # Ruby program for new() # method in Range # Initialize range range1 = Range.new(7, 9) # Prints the range puts range1 Output: 7..9 Comment More infoAdvertise with us Next Article Ruby | Range new() function gopaldave Follow Improve Article Tags : Ruby Ruby-Methods Ruby Range-class Similar Reads Ruby | Random new() function Random#new() : new() is a Random class method which creates a new PRNG using seed to set the initial state. Syntax: Random.new() Parameter: Random values Return: a new PRNG using seed to set the initial state. Example #1 : Ruby # Ruby code for Random.new() method # declaring Random value date_a = Ra 1 min read Ruby | Regexp new() function Regexp#new() : new() is a Regexp class method which returns a new regular expression pattern. Syntax: Regexp.new() Parameter: Regexp values Return: a new regular expression pattern Example #1 : Ruby # Ruby code for Regexp.new() method # declaring Regexp value reg_a = Regexp.new('/a/') # declaring Re 1 min read 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 include?() function 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 gi 1 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 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 | Queue new() function The new() is an inbuilt function in Ruby creates a new queue of the given name. Syntax: q_name = Queue.new() Parameters: The function does not takes any parameter. Return Value: It creates a new queue. Example 1: CPP #Ruby program for new () function in Queue #Create a new QUEUE q1 q1 = Queue.new #p 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 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 Like