ITNEXT

ITNEXT is a platform for IT developers & software engineers to share knowledge, connect…

Follow publication

Member-only story

A Ruby Cheatsheet For Arrays

Mike Cronin
ITNEXT
Published in
7 min readAug 15, 2019

--

Creating Arrays

arr = []
arr2 = Array.new
arr_with_stuff = ["value", "separated by comma"] 
arr_with_stuff2 = Array.new(["a", "b", "c"])
range_to_arr = (1..9).to_a
arr = Array.new(5, " ")
# -> [" ", " ", " ", " ", " "]
arr = %w(cat dog mouse 1 2)
# -> ["cat", "dog", "mouse", "1", "2"]

--

--

Published in ITNEXT

ITNEXT is a platform for IT developers & software engineers to share knowledge, connect, collaborate, learn and experience next-gen technologies.

Responses (2)

Write a response