Ruby | Array map() function Last Updated : 06 Dec, 2019 Summarize Comments Improve Suggest changes Share Like Article Like Report Array#map() : map() is a Array class method which returns a new array containing the values returned by the block. Syntax: Array.map() Parameter: Array Return: a new array containing the values returned by the block. Example #1 : Ruby # Ruby code for map() method # declaring array a = [18, 22, 33, 3, 5, 6] # declaring array b = [1, 4, 1, 1, 88, 9] # declaring array c = [18, 22, 3, 3, 50, 6] # map puts "map method : #{a.map {|num| num > 10 }}\n\n" # map puts "map method : #{b.map {|x| x.odd? }}\n\n" Output : map method : [true, true, true, false, false, false] map method : [true, false, true, true, false, true] Example #2 : Ruby # Ruby code for map() method # declaring array a = [18, 22, 33, 3, 5, 6] # declaring array b = [1, 4, 1, 1, 88, 9] # declaring array c = [18, 22, 3, 3, 53, 6] # map puts "map method : #{c.map {|num| num > 10 }}\n\n" # map puts "map method : #{c.map {|num| num.even? }}\n\n" Output : map method : [true, true, false, false, true, false] map method : [true, true, false, false, false, true] Comment More infoAdvertise with us Next Article Ruby | Array map() function M mayank5326 Follow Improve Article Tags : Ruby Ruby-Methods Ruby Array-class Similar Reads Ruby | Array pop() function Array#pop() : pop() is a Array class method which checks removes the last element from the array and returns it. Syntax: Array.pop() Parameter: Array Return: removes the last element from the array and returns it. Example #1 : Ruby # Ruby code for pop() method # declaring array a = [18, 22, 33, nil, 1 min read Ruby | Array push() function Array#push() : push() is a Array class method which appends the given object(s) on to the end of this array. Syntax: Array.push() Parameter: Array Return: appends the given object(s) on to the end of this array. Example #1 : Ruby # Ruby code for push() method # declaring array a = [18, 22, 33, nil, 2 min read Ruby | Array pack() function 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 : R 1 min read Ruby | Array one?() function Array#one?() : one?() is a Array class method which checks whether the array is having only one array element. Syntax: Array.one?() Parameter: Array Return: true - if array has only one element otherwise return false. Example #1 :Â Ruby # Ruby code for one?() method # declaring array a = [18, 22, 33 1 min read Ruby | Array rotate() function Array#rotate() : rotate() is a Array class method which returns a new array by rotating self so that the element at count is the first element of the new array. Syntax: Array.rotate() Parameter: Array Return: a new array by rotating self so that the element at count is the first element of the new a 2 min read Like