Sha256: d2e13157b997373815f7ff796a52a8eb72fc636c9ff185075b44839d067bafbf

Contents?: true

Size: 724 Bytes

Versions: 4

Compression:

Stored size: 724 Bytes

Contents

module Bogus
  class BaseClassIdentifier
    extend Takes
    takes :copied_class, :klass

    def self.base_class?(copied_class, klass)
      new(copied_class, klass).base_class?
    end

    def base_class?
      same? || included_module? || subclass?
    end

    private

    def same?
      klass == copied_class
    end

    def included_module?
      copied_class.included_modules.include?(klass)
    end

    def subclass?
      superclasses.include?(klass)
    end

    def superclasses
      return [] unless copied_class.is_a?(Class)
      klass = copied_class
      superclasses = []
      while klass
        superclasses << klass
        klass = klass.superclass
      end
      superclasses
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
bogus-0.1.7 lib/bogus/fakes/base_class_identifier.rb
bogus-0.1.6 lib/bogus/fakes/base_class_identifier.rb
bogus-0.1.5 lib/bogus/fakes/base_class_identifier.rb
bogus-0.1.4 lib/bogus/fakes/base_class_identifier.rb