Ruby | Hash to_s() function Last Updated : 07 Jan, 2020 Comments Improve Suggest changes Like Article Like Report Hash#to_s() is a Hash class method which gives the string representation of hash. Syntax: Hash.to_s() Parameter: Hash values Return: string representation of hash Example #1 : Ruby # Ruby code for Hash.to_s() method # declaring Hash value a = {a:100, b:200} # declaring Hash value b = {a:100, c:300, b:200} # declaring Hash value c = {a:100} # to_s Value puts "Hash a to_s form : #{a.to_s()}\n\n" puts "Hash b to_s form : #{b.to_s()}\n\n" puts "Hash c to_s form : #{c.to_s()}\n\n" Output : Hash a to_s form : {:a=>100, :b=>200} Hash b to_s form : {:a=>100, :c=>300, :b=>200} Hash c to_s form : {:a=>100} Example #2 : Ruby # Ruby code for Hash.to_s() method # declaring Hash value a = { "a" => 100, "b" => 200 } # declaring Hash value b = {"a" => 100} # declaring Hash value c = {"a" => 100, "c" => 300, "b" => 200} # to_s Value puts "Hash a to_s form : #{a.to_s()}\n\n" puts "Hash b to_s form : #{b.to_s()}\n\n" puts "Hash c to_s form : #{c.to_s()}\n\n" Output : Hash a to_s form : {"a"=>100, "b"=>200} Hash b to_s form : {"a"=>100} Hash c to_s form : {"a"=>100, "c"=>300, "b"=>200} Comment More infoAdvertise with us Next Article Ruby | Time hash function K Kirti_Mangal Follow Improve Article Tags : Ruby Ruby-Methods Ruby Hash-class Similar Reads Ruby | Vector hash() function The hash() is an inbuilt method in Ruby returns hash code of the vector Syntax: vec1.hash() Parameters: The function accepts no parameter. Return Value: It returns hash code of the vector. Example 1: Ruby # Ruby program for hash() method in Vector # Include matrix require "matrix" # Initia 1 min read Ruby | Vector hash() function The hash() is an inbuilt method in Ruby returns hash code of the vector Syntax: vec1.hash() Parameters: The function accepts no parameter. Return Value: It returns hash code of the vector. Example 1: Ruby # Ruby program for hash() method in Vector # Include matrix require "matrix" # Initia 1 min read Ruby | Vector hash() function The hash() is an inbuilt method in Ruby returns hash code of the vector Syntax: vec1.hash() Parameters: The function accepts no parameter. Return Value: It returns hash code of the vector. Example 1: Ruby # Ruby program for hash() method in Vector # Include matrix require "matrix" # Initia 1 min read Ruby | Time hash function Time#hash() : hash() is a Time class method which returns the hash code for this Time object. Syntax: Time.hash() Parameter: Time values Return: the hash code for this Time object. Example #1 : Ruby # Ruby code for Time.hash() method # declaring time a = Time.new(2019) # declaring time b = Time.new( 2 min read Ruby | Range to_s() function The to_s() is an inbuilt method in Ruby returns a string containing the given range. Syntax: range1.to_s() Parameters: The function accepts no parameter. Return Value: It returns a string containing the range. Example 1: Ruby # Ruby program for to_s() # method in Range # Initialize range range1 = (0 1 min read Ruby | Range to_s() function The to_s() is an inbuilt method in Ruby returns a string containing the given range. Syntax: range1.to_s() Parameters: The function accepts no parameter. Return Value: It returns a string containing the range. Example 1: Ruby # Ruby program for to_s() # method in Range # Initialize range range1 = (0 1 min read Like