Skip to content

Instantly share code, notes, and snippets.

@vagnerzampieri
Created September 30, 2013 22:49
Show Gist options
  • Select an option

  • Save vagnerzampieri/6771443 to your computer and use it in GitHub Desktop.

Select an option

Save vagnerzampieri/6771443 to your computer and use it in GitHub Desktop.
use reject! ruby
array = ['1', '', '2', '', 1, nil]
array.reject!(&:blank?)
=> [
[0] "1",
[1] "2",
[2] 1
]
@emaiax
Copy link
Copy Markdown

emaiax commented Oct 1, 2013

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(:&)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment