Last active
January 10, 2018 01:49
-
-
Save gbpereira/208e5b91a808b42860e9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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