Ruby | Regexp hash() function
Last Updated :
17 Dec, 2019
Regexp#force_encoding?() : force_encoding?() is a Regexp class method which returns the hash based on the text and options of this regular expression.
Syntax: Regexp.hash()
Parameter: Regexp values
Return: the hash based on the text and options of this regular expression.
Example #1 :
reg_a = /a/
reg_b = /geeks/
reg_c = /a/
puts "Regexp hash form : #{reg_a.hash}\n\n"
puts "Regexp hash form : #{reg_b.hash}\n\n"
puts "Regexp hash form : #{reg_c.hash}\n\n"
|
Output :
Regexp hash form : -1704400854280844509
Regexp hash form : -3140932202593119845
Regexp hash form : -1704400854280844509
Example #2 :
reg_a = /geeks/
reg_b = /problem/
reg_c = /code/
puts "Regexp hash form : #{reg_a.hash}\n\n"
puts "Regexp hash form : #{reg_b.hash}\n\n"
puts "Regexp hash form : #{reg_c.hash}\n\n"
|
Output :
Regexp hash form : -429624664738525607
Regexp hash form : -2782281071524532422
Regexp hash form : -3545766771755419715
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...