lib/tapioca/runtime/reflection.rb in tapioca-0.11.16 vs lib/tapioca/runtime/reflection.rb in tapioca-0.11.17

- old
+ new

@@ -253,8 +253,25 @@ sig { params(method: UnboundMethod).returns(T::Boolean) } def method_defined_by_forwardable_module?(method) method.source_location&.first == Object.const_source_location(:Forwardable)&.first end + + sig { params(name: String).returns(T::Boolean) } + def has_aliased_namespace?(name) + name_parts = name.split("::") + name_parts.pop # drop the constant name, leaving just the namespace + + name_parts.each_with_object([]) do |name_part, namespaces| + namespaces << "#{namespaces.last}::#{name_part}".delete_prefix("::") + end.any? do |namespace| + constant = constantize(namespace) + next unless Module === constant + + # If the constant name doesn't match the namespace, + # the namespace must contain an alias + name_of(constant) != namespace + end + end end end end