Sha256: d338c64dfbb36edaf745406f2c8e8ee8ac97c76c525649f7b1987033a2763064

Contents?: true

Size: 1.12 KB

Versions: 3

Compression:

Stored size: 1.12 KB

Contents

class Array
  # Compares two arrays to see if the elements are same but simply rearranged.
  def rearranges?(*other_ary)
    Set.new(self) == Set.new(other_ary.flatten_splat)
  end
  
  def subset?(other_ary)
    other_ary.is_a?(Array) or raise ArgumentError, "Other array in argument must be an Array"
    Set.new(self).subset?(Set.new(other_ary))
  end
  
  def is_included_in?(other_ary)
    other_ary.is_a?(Array) or raise ArgumentError, "Other array in argument must be an Array"
    super || subset?(other_ary)
  end
  
  # Careful with this. This means 4 out of 5 elements can be the same but if not all of this self Array object are a part of other_ary,
  # this returns true, as in "Yes, depite having 4 out of 5 in other_ary, I am excluded from the other_ary."
  def is_excluded_from?(other_ary)
    other_ary.is_a?(Array) or raise ArgumentError, "Other array in argument must be an Array"
    super || not_subset?(other_ary)
  end

  alias_method :include_one?, :include?
  def include_all?(*other_ary)
    other_ary.flatten_splat!
    include_one(other_ary) || superset?(other_ary)
  end #alias_method :include?,     :include_all?
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
core_utilities-0.1.3 lib/core_utilities/core_ext/array/base.rb
core_utilities-0.1.1 lib/core_utilities/core_ext/array/base.rb
core_utilities-0.1.0 lib/core_utilities/core_ext/array/base.rb