Method: ShopifyCLI::MethodObject::ClassMethods#call
- Defined in:
- lib/shopify_cli/method_object.rb
#call ⇒ Object
creates a new instance and invokes call. Any positional argument is forward to call. Keyword arguments are either forwarded to the initializer or to call. If the keyword argument matches the name of property, it is forwarded to the initializer, otherwise to call.
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/shopify_cli/method_object.rb', line 69 ruby2_keywords def call(*args, &block) # This is an extremely complicated case of delegation. The method wants # to delegate arguments, but to have control over which keyword # arguments are delegated. I'm not sure the forward and backward # compatibility of this unusual form of delegation has really been # explored or there's any good way to support it. So I have done # done something hacky here and I'm looking at the last argument and # modifying the package of arguments to be delegated in-place. if args.last.is_a?(Hash) kwargs = args.last initializer_kwargs = kwargs.slice(*properties.keys) instance = new(**initializer_kwargs) kwargs.reject! { |key| initializer_kwargs.key?(key) } args.pop if kwargs.empty? instance.call(*args, &block) else # Since the former is so complicated - let's have a fast path that # is much simpler. new.call(*args, &block) end end |