Skip to content

Instantly share code, notes, and snippets.

@iJKTen
Created June 10, 2020 20:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iJKTen/526c5b36248c2bf1ff42c5d8b64f0821 to your computer and use it in GitHub Desktop.
Save iJKTen/526c5b36248c2bf1ff42c5d8b64f0821 to your computer and use it in GitHub Desktop.
arr = []
// Another way to declare an array
arr = Array.new
arr.push(1)
# append is an alias for push
arr.append(2)
arr.insert(2, 3)
# we can pass multiple items to the array
arr.push(4, 5, 6, 7, 8)
arr[0]
arr[1]
arr[2]
arr[3]
arr[4]
arr[5]
arr[6]
arr[7]
for item in arr do
puts item
end
arr.each_with_index do |item, index|
puts index, item
end
arr.each {|item|
puts item
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment