Ruby | Range each() function Last Updated : 18 Dec, 2019 Comments Improve Suggest changes Like Article Like Report 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 for each method in Range # Initialize range range1 = (0..10) # Prints elements puts range1.each {|el| print el, ',' } Output: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 0..10 Example 2: Ruby # Ruby program for each method in Range # Initialize range range1 = (6..12) # Prints elements puts range1.each{|el| print el, ',' } Output: 6, 7, 8, 9, 10, 11, 12, 6..12 Comment More infoAdvertise with us Next Article Ruby | Range each() function gopaldave Follow Improve Article Tags : Ruby Ruby-Methods Ruby Range-class Similar Reads 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 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 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 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 | Hash each() function Hash#each() is a Hash class method which finds the nested value which calls block once for each key in hash by passing the key-value pair as parameters. Syntax: Hash.each() Parameter: Hash values Return: calls block once for each key in hash otherwise Enumerator if no argument is passed. Example #1 2 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 | Hash each_key function Hash#each_key() is a Hash class method which finds the nested value which calls block once for each_key pair in the hash by passing the key as parameters. Syntax: Hash.each_key() Parameter: Hash values Return: calls block once for key_value pair in hash with key as a parameter otherwise, Enumerator 2 min read Ruby | Hash each_key() function Hash#each_key() is a Hash class method which finds the nested value which calls block once for each_key key in hash by passing the key pair as parameters. Syntax: Hash.each_key() Parameter: Hash values Return: calls block once for each_key key in hash with key as parameter otherwise Enumerator if no 2 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