Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix FAQ: block params shadow outer lvars #2851

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions en/documentation/faq/4/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -361,19 +361,20 @@ the method is invoked. It is evaluated using the scope of the method.

### How do I pass arguments to a block?

Typically, arguments are passed to a block using `yield` (or an iterator
that calls `yield`), or by using the `Proc.call` method.
Copy link
Author

Choose a reason for hiding this comment

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

I had previously just moved this paragraph to the top, but it should also be altered to use the appropriate syntax to indicate an instance method on Proc. I prefer the # syntax, but this should use whichever is most consistent with other parts of this FAQ.

Suggested change
that calls `yield`), or by using the `Proc.call` method.
that calls `yield`), or by using the `proc.call` method.
Suggested change
that calls `yield`), or by using the `Proc.call` method.
that calls `yield`), or by using the `Proc#call` method.


The formal parameters of a block appear between vertical bars at the start
of the block:

~~~
proc {|a, b| a <=> b }
~~~

These parameters are actually local variables. If an existing local variable
of the same name exists when the block executes, that variable will be
modified by the call to the block. This may or may not be a good thing.

Typically, arguments are passed to a block using `yield` (or an iterator that
calls `yield`), or by using the `Proc.call` method.
These parameters are actually local variables, scoped to that block. If a
local variable with the same name as a block parameter exists when the
block is defined, that outer variable will be "shadowed" (hidden) inside the
block by the block parameter. This may or may not be a good thing.

### Why did my object change unexpectedly?

Expand Down