Sha256: 5a01d5c49cc1637773e87de2d3421d0bdcc160b35f13c25726d31848cbdcd90b

Contents?: true

Size: 1.15 KB

Versions: 64

Compression:

Stored size: 1.15 KB

Contents

module Danger
  module Helpers
    module ArraySubclass
      include Comparable

      def initialize(array)
        @__array__ = array
      end

      def kind_of?(compare_class)
        return true if compare_class == self.class

        dummy.kind_of?(compare_class)
      end

      def method_missing(name, *args, &block)
        super unless __array__.respond_to?(name)

        respond_to_method(name, *args, &block)
      end

      def respond_to_missing?(name)
        __array__.respond_to?(name) || super
      end

      def to_a
        __array__
      end

      def to_ary
        __array__
      end

      def <=>(other)
        return unless other.kind_of?(self.class)

        __array__ <=> other.instance_variable_get(:@__array__)
      end

      private

      attr_accessor :__array__

      def dummy
        Class.new(Array).new
      end

      def respond_to_method(name, *args, &block)
        result = __array__.send(name, *args, &block)
        return result unless result.kind_of?(Array)

        if name =~ /!/
          __array__ = result
          self
        else
          self.class.new(result)
        end
      end
    end
  end
end

Version data entries

64 entries across 64 versions & 1 rubygems

Version Path
danger-5.12.0 lib/danger/helpers/array_subclass.rb
danger-5.11.1 lib/danger/helpers/array_subclass.rb
danger-5.11.0 lib/danger/helpers/array_subclass.rb
danger-5.10.3 lib/danger/helpers/array_subclass.rb
danger-5.10.2 lib/danger/helpers/array_subclass.rb
danger-5.10.1 lib/danger/helpers/array_subclass.rb
danger-5.10.0 lib/danger/helpers/array_subclass.rb
danger-5.9.1 lib/danger/helpers/array_subclass.rb
danger-5.9.0 lib/danger/helpers/array_subclass.rb
danger-5.8.2 lib/danger/helpers/array_subclass.rb
danger-5.8.1 lib/danger/helpers/array_subclass.rb
danger-5.8.0 lib/danger/helpers/array_subclass.rb
danger-5.7.1 lib/danger/helpers/array_subclass.rb
danger-5.7.0 lib/danger/helpers/array_subclass.rb
danger-5.6.7 lib/danger/helpers/array_subclass.rb
danger-5.6.6 lib/danger/helpers/array_subclass.rb
danger-5.6.5 lib/danger/helpers/array_subclass.rb
danger-5.6.4 lib/danger/helpers/array_subclass.rb
danger-5.6.3 lib/danger/helpers/array_subclass.rb
danger-5.6.2 lib/danger/helpers/array_subclass.rb