Last Updated: February 25, 2016
·
555
· bunnymatic

Ruby Enumerable#some?

Ruby's Enumerable module has #any?, #none?, and #all? We just hit a scenario where we really wanted to know if it had some but not all...

module Enumerable
  def some?
    self.any? && !self.all?
  end
end

Examples:

irb> [1,2,3].some?
=> false
irb> [1,2,nil].some?
=> true
irb> [nil].some?
=> false
irb> [].some?
=> false