Ruby | Array class inspect() function
Inspect() is an Array class method which returns the all array elements.
Syntax: Array.inspect()
Parameter: Array
Return: all array elements
Example #1 :
a = [ 18 , 22 , 33 , nil , 5 , 6 ]
b = [ 1 , 4 , 1 , 1 , 88 , 9 ]
c = [ 18 , 22 , nil , nil , 50 , 6 ]
puts "inspect : #{a.inspect()}\n\n"
puts "inspect : #{b.inspect()}\n\n"
puts "inspect : #{c.inspect()}\n\n"
|
Output :
inspect : [18, 22, 33, nil, 5, 6]
inspect : [1, 4, 1, 1, 88, 9]
inspect : [18, 22, nil, nil, 50, 6]
Example #2 :
a = [ "abc" , "nil" , "dog" ]
b = [ "cow" , nil , "dog" ]
c = [ "cat" , nil , nil ]
puts "inspect : #{a.inspect()}\n\n"
puts "inspect : #{b.inspect()}\n\n"
puts "inspect : #{c.inspect()}\n\n"
|
Output :
inspect : ["abc", "nil", "dog"]
inspect : ["cow", nil, "dog"]
inspect : ["cat", nil, nil]
Last Updated :
07 Jan, 2020
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...