Skip to content

Instantly share code, notes, and snippets.

@gbpereira
Last active January 10, 2018 01:49
Show Gist options
  • Save gbpereira/208e5b91a808b42860e9 to your computer and use it in GitHub Desktop.
Save gbpereira/208e5b91a808b42860e9 to your computer and use it in GitHub Desktop.
# algumas formas de inicializar um array
arr = [] # []
arr = [1, 2, 3] # [1, 2, 3]
arr = *(1..3) # [1, 2, 3]
arr = Array(1..3) # [1, 2, 3]
arr = Array.new # []
arr = Array.new(4) # [nil, nil, nil, nil]
arr = Array.new(4, 2) # [2, 2, 2, 2]
# arrays podem conter tipos diferentes de dados
arr = [1, 'a', {a: 'a', b: 'b'}, [1, 2], (1..4)]
# a classe Array utiliza os operadores | e & para união e intersecção
a = [1, 2, 3, 4]
b = [5, 4, 3, 2]
a | b # [1, 2, 3, 4, 5]
a & b # [2, 3, 4]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment