Module: MoreCoreExtensions::ArrayInclusions
- Defined in:
- lib/more_core_extensions/core_ext/array/inclusions.rb
Instance Method Summary collapse
-
#include_all?(*items) ⇒ Boolean
Returns whether the Array contains all of the items.
-
#include_any?(*items) ⇒ Boolean
Returns whether the Array contains any of the items.
-
#include_none?(*items) ⇒ Boolean
Returns whether the Array contains none of the items.
-
#includes_index?(index) ⇒ Boolean
Returns whether the Array has a value at the index.
Instance Method Details
#include_all?(*items) ⇒ Boolean
Returns whether the Array contains all of the items.
[1, 2, 3].include_all?(1, 2) #=> true
[1, 2, 3].include_all?(1, 4) #=> false
[1, 2, 3].include_all?(4, 5) #=> false
31 32 33 34 |
# File 'lib/more_core_extensions/core_ext/array/inclusions.rb', line 31 def include_all?(*items) items = items.first if items.length == 1 && items.first.kind_of?(Array) (items - self).empty? end |
#include_any?(*items) ⇒ Boolean
Returns whether the Array contains any of the items.
[1, 2, 3].include_any?(1, 2) #=> true
[1, 2, 3].include_any?(1, 4) #=> true
[1, 2, 3].include_any?(4, 5) #=> false
9 10 11 12 |
# File 'lib/more_core_extensions/core_ext/array/inclusions.rb', line 9 def include_any?(*items) items = items.first if items.length == 1 && items.first.kind_of?(Array) !(self & items).empty? end |
#include_none?(*items) ⇒ Boolean
Returns whether the Array contains none of the items.
[1, 2, 3].include_none?(1, 2) #=> false
[1, 2, 3].include_none?(1, 4) #=> false
[1, 2, 3].include_none?(4, 5) #=> true
20 21 22 23 |
# File 'lib/more_core_extensions/core_ext/array/inclusions.rb', line 20 def include_none?(*items) items = items.first if items.length == 1 && items.first.kind_of?(Array) (self & items).empty? end |
#includes_index?(index) ⇒ Boolean
Returns whether the Array has a value at the index.
[1, 2, 3].includes_index?(-4) #=> false
[1, 2, 3].includes_index?(-3) #=> true
[1, 2, 3].includes_index?(1) #=> true
[1, 2, 3].includes_index?(2) #=> true
[1, 2, 3].includes_index?(3) #=> false
44 45 46 |
# File 'lib/more_core_extensions/core_ext/array/inclusions.rb', line 44 def includes_index?(index) (-self.length...self.length).cover?(index) end |