belongs to collection: Ruby Hashes Programs
In this program, we will create 3 variables with hash values. Then we will use inspect() function to get the value of the variable as a string.
Program/Source Code:
The source code to demonstrate the Hash.inspect() function is given below. The given program is compiled and executed successfully.
# Ruby program to demonstrate the # Hash.inspect() function. # Declaration of hash values. num1 = {a:10, b:15}; num2 = {a:10, b:15, c:20}; num3 = {a:10, b:15, c:20, d:25}; print "Num1: " ,num1.inspect(); print "\nNum2: ",num2.inspect(); print "\nNum3: ",num3.inspect();
Output:
Num1: {:a=>10, :b=>15} Num2: {:a=>10, :b=>15, :c=>20} Num3: {:a=>10, :b=>15, :c=>20, :d=>25}
Explanation:
In the above program, we created three variables with some hash values. Then we used inspect() function with created variable to get values of variables as a string and printed the result.
total answers (1)
start bookmarking useful questions and collections and save it into your own study-lists, login now to start creating your own collections.
Program/Source Code:
The source code to demonstrate the Hash.inspect() function is given below. The given program is compiled and executed successfully.
Output:
Explanation:
In the above program, we created three variables with some hash values. Then we used inspect() function with created variable to get values of variables as a string and printed the result.
need an explanation for this answer? contact us directly to get an explanation for this answer