hash is a String class method in Ruby which is used to return a hash based on the string’s length, content and encoding.
Syntax: str.hash
Parameters: Here, str is the given string.
Returns: A hash based on the string’s length, content and encoding.
Example 1:
# Ruby program to demonstrate # the hash method # Taking a string and # using the method puts "Ruby".hash puts "String".hash |
chevron_right
filter_none
Output:
3142682481284465636 -3118341609802567384
Example 2:
# Ruby program to demonstrate # the hash method # Taking a string and # using the method puts "Sample".hash puts "Program".hash |
chevron_right
filter_none
Output:
1285954436548758293 -6969951348417810
Recommended Posts:
- Ruby | Hash value? method
- Ruby | Hash > method
- Ruby | Hash < method
- Ruby | Hash select() method
- Ruby | Hash select!() method
- Ruby | Hash to_h method
- Ruby | Hash class <= method
- Ruby | Hash to_proc method
- Ruby | Hash shift() method
- Ruby | Hash length() method
- Ruby | Hash reject! method
- Ruby | Hash to_a method
- Ruby | Hash reject method
- Ruby | Hash store() method
- Ruby | Hash values_at method
- Ruby | Hash to_s method
- Ruby | Hash size() method
- Ruby | Hash class >= method
- Ruby | Hash replace() method
- Ruby | Hash to_hash method
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

