Skip to content

Add anonymous block forwarding: def b; c(&) end#5051

Merged
jeremyevans merged 1 commit intoruby:masterfrom
jeremyevans:anon-block-forwarding-11256
Nov 18, 2021
Merged

Add anonymous block forwarding: def b; c(&) end#5051
jeremyevans merged 1 commit intoruby:masterfrom
jeremyevans:anon-block-forwarding-11256

Conversation

@jeremyevans
Copy link
Copy Markdown
Contributor

Anonymous block forwarding allows a method to forward a passed
block to another method without having to provide a name for the
block parameter.

Implements [Feature #11256]

I'll update the documentation for this if it is accepted.

Co-authored-by: Yusuke Endoh mame@ruby-lang.org
Co-authored-by: Nobuyoshi Nakada nobu@ruby-lang.org

@jeremyevans jeremyevans requested review from mame and nobu October 28, 2021 22:00
@casperisfine
Copy link
Copy Markdown
Contributor

Could you add some tests in test/ruby/test_iseq.rb ? I fear that this new anonymous parameter might cause a bug similar to #5035 / #4961

block to another method without having to provide a name for the
block parameter.

Implements [Feature ruby#11256]

Co-authored-by: Yusuke Endoh mame@ruby-lang.org
Co-authored-by: Nobuyoshi Nakada nobu@ruby-lang.org
@jeremyevans jeremyevans force-pushed the anon-block-forwarding-11256 branch from 8558eb4 to a9ace6c Compare November 18, 2021 20:45
@jeremyevans
Copy link
Copy Markdown
Contributor Author

I rebased this against master and made the changes requested by matz to not allow def c; d(&) end. This makes the patch much simpler. @casperisfine I included a couple of tests in test_iseq.c, please let me know if you think additional tests should be added.

@jeremyevans jeremyevans merged commit 4adb012 into ruby:master Nov 18, 2021

def test_super_with_anonymous_block
iseq = compile(<<~EOF)
def touch3(&block) # :nodoc:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you meant def touch3(&) # :nodoc: here, no?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, I'll fix that.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Submitted a PR for it: #5147

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants