Ruby | Array pack() function
Last Updated :
06 Dec, 2019
Array#pack() : pack() is a Array class method which returns the contents of arr into a binary sequence according to the directives in aTemplateString
Syntax: Array.pack()
Parameter: Array
Return: the contents of arr into a binary sequence according to the directives in aTemplateString
Example #1 :
a = [ 18 , 22 , 33 , nil , 5 , 6 ]
b = [ 1 , 4 , 1 , 1 , 88 , 9 ]
c = [ 2 , 3 , 1 , 8 ]
puts "pack() method form : #{a.pack(" ccc ")}\n\n"
puts "pack() method form : #{b.pack(" efe ")}\n\n"
|
Output :
pack() method form : !
pack() method form :
Example #2 :
a = [ "abc" , "nil" , "dog" ]
b = [ "cow" , nil , "dog" ]
c = [ "maths" ]
puts "pack() method form : #{a.pack(" A3A3A3 ")}\n\n"
puts "pack() method form : #{b.pack(" a3a3a3 ")}\n\n"
|
Output :
pack() method form : abcnildog
pack() method form : cowdog
Share your thoughts in the comments
Please Login to comment...