Skip to content

Commit

Permalink
Delegate keyword arguments in Prawn::View#method_missing
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Burgestrand authored and pointlessone committed Jan 8, 2024
1 parent 4e8a9c9 commit d7d4a8e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions lib/prawn/view.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions spec/prawn/view_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit d7d4a8e

Please sign in to comment.