Skip to content

#each's return takes precendence over inner block's return with a lambda #3143

@robin850

Description

@robin850

Hello,

There's a behavioral difference between JRuby and MRI when calling #each. If a lambda with a return statement is called inside #each, the result of the latter will be returned rather than the lambda's one:

require 'minitest/autorun'

class LambdaTest < Minitest::Test
  def bar(&b)
    [1].each { -> { self.instance_exec(&b) }.call }
  end

  def test_return_with_lambda
    assert_equal "foo", bar { return "foo" }
  end
end

Have a nice day!

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions