Ruby | Array to_s() function Last Updated : 06 Dec, 2019 Comments Improve Suggest changes 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 sort() function Array#sort() : sort() is a Array class method which returns a new array created by sorting self Syntax: Array.sort() Parameter: Array Return: a new array created by sorting self Example #1 : Ruby # Ruby code for sort() method # declaring array a = ["abc", "nil", "dog"] 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 Ruby | Array take() function Array#take() : take() is a Array class method which returns the number of elements in the array. Syntax: Array.take() Parameter: Array Return: the number of elements in the array. Example #1 : Ruby # Ruby code for take() method # declaring array a = [18, 22, 33, nil, 5, 6] # declaring array b = [1, 1 min read Ruby | Array select() function Array#select() : select() is a Array class method which returns a new array containing all elements of array for which the given block returns a true value. Syntax: Array.select() Parameter: Array Return: A new array containing all elements of array for which the given block returns a true value. Ex 2 min read Ruby | Array unshift() function Array#unshift() : unshift() is a Array class method which returns the shifted array with argumented element in place. Syntax: Array.unshift()Parameter: ArrayReturn: the shifted array with argumented element in place. Example #1 : Ruby # Ruby code for unshift() method # declaring array a = [18, 22, 3 2 min read Like