lib/parlour/rbi_generator/class_namespace.rb in parlour-1.0.0 vs lib/parlour/rbi_generator/class_namespace.rb in parlour-2.0.0

- old
+ new

@@ -68,23 +68,25 @@ sig do override.params( others: T::Array[RbiGenerator::RbiObject] ).returns(T::Boolean) end - # Given an array of {ClassNamespace} instances, returns true if they may + # Given an array of {Namespace} instances, returns true if they may # be merged into this instance using {merge_into_self}. For instances to # be mergeable, they must either all be abstract or all not be abstract, # and they must define the same superclass (or none at all). # - # @param others [Array<RbiGenerator::RbiObject>] An array of other {ClassNamespace} instances. + # @param others [Array<RbiGenerator::RbiObject>] An array of other {Namespace} instances. # @return [Boolean] Whether this instance may be merged with them. def mergeable?(others) - others = T.cast(others, T::Array[ClassNamespace]) rescue (return false) + others = T.cast(others, T::Array[Namespace]) rescue (return false) all = others + [self] - all.map(&:abstract).uniq.length == 1 && - all.map(&:superclass).compact.uniq.length <= 1 + all_classes = T.cast(all.select { |x| ClassNamespace === x }, T::Array[ClassNamespace]) + + all_classes.map(&:abstract).uniq.length == 1 && + all_classes.map(&:superclass).compact.uniq.length <= 1 end sig do override.params( others: T::Array[RbiGenerator::RbiObject] @@ -97,9 +99,10 @@ # @return [void] def merge_into_self(others) super others.each do |other| + next unless ClassNamespace === other other = T.cast(other, ClassNamespace) @superclass = other.superclass unless superclass end end