Created
September 30, 2013 22:49
-
-
Save vagnerzampieri/6771443 to your computer and use it in GitHub Desktop.
use reject! ruby
This file contains hidden or 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
| array = ['1', '', '2', '', 1, nil] | |
| array.reject!(&:blank?) | |
| => [ | |
| [0] "1", | |
| [1] "2", | |
| [2] 1 | |
| ] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
tempos atrás tive um caso em que tinha alguns arrays e precisava achar a interseção entre todos eles, o jeito foi o reject nos vazios e interseção no que sobrou.
a = [1, 2]
b = [1, 3, 4]
c = []
[a, b, c].reject(&:empty?).inject(:&)