Skip to content

Comments

fix: middleware example to correctly return yield result#354

Open
S0nee wants to merge 1 commit intocoinbase:masterfrom
S0nee:master-readme
Open

fix: middleware example to correctly return yield result#354
S0nee wants to merge 1 commit intocoinbase:masterfrom
S0nee:master-readme

Conversation

@S0nee
Copy link

@S0nee S0nee commented Feb 22, 2026

In the Middleware code block, the example in README was incorrect:

class MyMiddleware
  def call(metadata)
    puts "Before execution"
    yield
    puts "After execution"
    result
  end
end

Why this is wrong:

  • The variable result is used, but it is not assigned anywhere.
  • The method does not return a yield result.

Correction:

class MyMiddleware
  def call(metadata)
    puts "Before execution"
    result = yield
    puts "After execution"
    result
  end
end

Now, an example:

  • Stores the result of executing the block in result.
  • Explicitly returns the result of the block, allowing the middleware chain to pass values correctly.

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

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant