Skip to content

Instantly share code, notes, and snippets.

@surrealdetective
Created June 10, 2013 20:06
Show Gist options
  • Save surrealdetective/5751802 to your computer and use it in GitHub Desktop.
Save surrealdetective/5751802 to your computer and use it in GitHub Desktop.
arrays
# Construct an array with your favorite foods. It should have at least 5 elements.
# Write a puts which returns your most favorite food out of the array.
fav_foods = ['lasagna', 'salmon', 'avocado', 'grapefruit', 'milkshake']
puts fav_foods[1]
# Construct an array with the colors of the rainbow (ROYGBIV)
# Slice the colors Red, Orange, and Yellow out of the array.
colors = ['Red', 'Orange', 'Yellow', 'Green', 'Blue', 'Indigo', 'Violet']
colors.slice(3, 6)
# Create an empty array.
# Assign values to the the second and 6th position.
test_array = []
test_array[1] = 'This is the 2nd position.'
test_array[5] = 'This is the 6th position.'
test_array
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment