Ruby | String hash method Last Updated : 12 Dec, 2019 Summarize Comments Improve Suggest changes Share Like Article Like Report 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 # Ruby program to demonstrate # the hash method # Taking a string and # using the method puts "Ruby".hash puts "String".hash Output: 3142682481284465636 -3118341609802567384 Example 2: Ruby # Ruby program to demonstrate # the hash method # Taking a string and # using the method puts "Sample".hash puts "Program".hash Output: 1285954436548758293 -6969951348417810 Comment More infoAdvertise with us Next Article Ruby | String hash method K Kirti_Mangal Follow Improve Article Tags : Ruby Ruby-Methods Ruby String-class Similar Reads Ruby | String chars() Method chars is a String class method in Ruby which is used to return an array of characters in str. Syntax: str.chars Parameters: Here, str is the given string Returns: An array of the characters. Example 1: Ruby # Ruby program to demonstrate # the chars method # Taking a string and # using the method put 1 min read Ruby | Hash store() method Hash#store() is a Hash class method that returns an add-on value with the key given by the key-value argument. Syntax: Hash.store()Parameter: Hash values key valueReturn: add on value with the key given by the key-value argument. Example #1 : Ruby # Ruby code for Hash.store() method # declaring H 2 min read Ruby | String hex Method hex is a String class method in Ruby which is used to treats the leading characters from the given string as a string of hexadecimal digits (with an optional sign and an optional 0x) and returns the corresponding number. Zero is returned on error. Syntax: str.hex Parameters: Here, str is the given s 1 min read Ruby | String * Method String# * is a String class method in Ruby which is used to returns a new String containing integer copies of the receiver. Here, integer must be greater than or equal to 0. Syntax: str * Integer Parameters: Here, str is the required string and integer is the number of copies. Returns: This method r 1 min read Ruby | String =~ Method =~() is a String class method in Ruby which is used for matching purpose. If the given object is a Regexp, then this method will use it as a pattern to match against the given string. Syntax: str =~ obj Parameters: Here, str is the given string and obj is the object to be matched. Returns: The posit 1 min read Like