From d7d4a8e9505d0ea3acb472a08b9872994ee248f5 Mon Sep 17 00:00:00 2001 From: Kim Burgestrand Date: Thu, 26 Jan 2023 13:58:40 +0100 Subject: [PATCH] Delegate keyword arguments in Prawn::View#method_missing Come Ruby 3.x, keyword arguments will not be part of `*arguments` any more. We could either: 1. Mark the method with `ruby2_keywords`, which would make keyword arguments part of `*arguments` again. However, this is going away in the future so it's a crutch if anything. 2. Make the method properly support keyword arguments. Option 2 is chosen here. --- lib/prawn/view.rb | 4 ++-- spec/prawn/view_spec.rb | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/prawn/view.rb b/lib/prawn/view.rb index dbee949e0..c51436bb8 100644 --- a/lib/prawn/view.rb +++ b/lib/prawn/view.rb @@ -69,10 +69,10 @@ def document # Delegates all unhandled calls to object returned by +document+ method. # (which is an instance of Prawn::Document by default) - def method_missing(method_name, *arguments, &block) + def method_missing(method_name, *args, **kwargs, &block) return super unless document.respond_to?(method_name) - document.public_send(method_name, *arguments, &block) + document.public_send(method_name, *args, **kwargs, &block) end def respond_to_missing?(method_name, _include_all = false) diff --git a/spec/prawn/view_spec.rb b/spec/prawn/view_spec.rb index 237822a0f..3cf937b48 100644 --- a/spec/prawn/view_spec.rb +++ b/spec/prawn/view_spec.rb @@ -12,12 +12,12 @@ it 'delegates unhandled methods to object returned by document method' do doc = instance_double('Document') allow(view_object).to receive(:document).and_return(doc) - allow(doc).to receive(:some_delegated_method) + block = proc {} - view_object.some_delegated_method + view_object.some_delegated_method('positional', keyword: 'argument', &block) - expect(doc).to have_received(:some_delegated_method) + expect(doc).to have_received(:some_delegated_method).with('positional', keyword: 'argument', &block) end it 'allows a block-like DSL via the update method' do