Sorbet sig conflict with ViewComponent collection rendering
Published on
Error message:
FooComponent initializer must accept `foo` collection parameter.
Solutions that didn't work:
-
::Method.prepend(T::CompatibilityPatches::MethodExtensions)
The methods we're looking at turn out to be
::UnboundMethod
instances. -
::UnboundMethod.prepend(T::CompatibilityPatches::MethodExtensions)
Infinite recursion somehow!
Solution that did work:
base.singleton_class.send(:prepend, ClassMethods)
end
initialize = instance_method(:initialize)
# Copied from T::CompaibilityPatches::MethodExtensions#parameters
sig = T::Private::Methods.signature_for_method(initialize)
sig ? sig.method.parameters : super
end
end
end
ViewComponent::Base.prepend(ViewComponentSorbetMonkeyPatch)
I'll definitely be cleaning this up and writing a real blog post about it. This deserves a real explanation but I have to find one first!