Ruby | Array to_s() function Last Updated : 06 Dec, 2019 Summarize Comments Improve Suggest changes Share Like Article Like Report Array#to_s() : to_s() is a Array class method which returns self array. Syntax: Array.to_s() Parameter: Array Return: self array Example #1 : Ruby # Ruby code for to_s() method # declaring array a = [18, 22, 33, nil, 5, 6] # declaring array b = [1, 4, 1, 1, 88, 9] # declaring array c = [18, 22, 50, 6] # to_s method example puts "to_s() method form : #{a.to_s()}\n\n" puts "to_s() method form : #{b.to_s()}\n\n" puts "to_s() method form : #{c.to_s()}\n\n" Output : to_s() method form : [18, 22, 33, nil, 5, 6] to_s() method form : [1, 4, 1, 1, 88, 9] to_s() method form : [18, 22, 50, 6] Example #2 : Ruby # Ruby code for to_s() method # declaring array a = ["abc", "nil", "dog"] # declaring array c = ["cat", nil] # declaring array b = ["cow", nil, "dog"] # to_s method example puts "to_s() method form : #{a.to_s()}\n\n" puts "to_s() method form : #{b.to_s()}\n\n" puts "to_s() method form : #{c.to_s()}\n\n" Output : to_s() method form : ["abc", "nil", "dog"] to_s() method form : ["cow", nil, "dog"] to_s() method form : ["cat", nil] Comment More infoAdvertise with us Next Article Ruby | Array to_s() function M mayank5326 Follow Improve Article Tags : Ruby Ruby-Methods Ruby Array-class Similar Reads Ruby | Array to_a() function Array#to_a() : to_a() is a Array class method which returns self array. Syntax: Array.to_a() Parameter: Array Return: self array representation Example #1 : Ruby # Ruby code for to_a() method # declaring array a = [18, 22, 33, nil, 5, 6] # declaring array b = [1, 4, 1, 1, 88, 9] # declaring array c 1 min read Ruby | Array to_h() function Array#to_h() : to_h() is a Array class method which returns the result of interpreting ary as an array of [key, value] pairs. Syntax: Array.to_h() Parameter: Array Return: the result of interpreting ary as an array of [key, value] pairs. Example #1 : Ruby # Ruby code for to_h() method # declaring ar 1 min read Ruby | Array shift() function Array#shift() : shift() is a Array class method which removes the first element of self and returns it or nil if the array is empty. Syntax: Array.shift() Parameter: Array Return: removes the first element of self and returns it or nil if the array is empty. Example #1 : Ruby # Ruby code for shift() 2 min read Ruby | Array class to_s() function to_s() is an Array class method which returns the string representation of the array elements. Syntax: Array.to_s() Parameter: Array Return: string representation of the array elements. Example #1: Ruby # Ruby code for to_s() method # declaring array a = [18, 22, 33, nil, 5, 6] # declaring array b = 1 min read Ruby | Array to_ary() function Array#to_ary() : to_ary() is a Array class method which returns self array representation. Syntax: Array.to_ary() Parameter: Array Return: self array representation. Example #1 : Ruby # Ruby code for to_ary() method # declaring array a = [18, 22, 33, nil, 5, 6] # declaring array b = [1, 4, 1, 1, 88, 1 min read Like