Skip to content

Instantly share code, notes, and snippets.

@sunny
Last active September 7, 2019 16:16
Show Gist options
  • Save sunny/8b99ee8fe243a069e2f1a19e61c16ec2 to your computer and use it in GitHub Desktop.
Save sunny/8b99ee8fe243a069e2f1a19e61c16ec2 to your computer and use it in GitHub Desktop.
Adds #compact to Lazy Enumerators in Ruby
class Enumerator::Lazy
def compact
reject(&:nil?)
end
end
@Nakilon
Copy link

Nakilon commented Sep 6, 2019

Wrong, you should use reject(&:nil?) otherwise you reject false too.

@sunny
Copy link
Author

sunny commented Sep 7, 2019

Good catch, Nakilon! Updated.

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