Open In App

Ruby | Range hash() function

Last Updated : 19 Mar, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report
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() 
# method in Range 

# Initialize range 
range1 = (0..10)

# Prints hash value
puts range1.hash()
Output:
2205001427131717671
Example 2: Ruby
# Ruby program for hash() 
# method in Range 

# Initialize range 
range1 = (3..6)

# Prints hash value
puts range1.hash()
Output:
-377246730583736123

Next Article

Similar Reads