wcgj2w
Last Updated: February 25, 2016
·
350
· bunnymatic
11d948cbd083298dea9f4f32c71f6427

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
Say Thanks
Respond