This is the code. I expect to see the string “Afterward:turkey”, but
why am I getting “Afterward:camel”? |animal| parameter in a block
should be temporary inside the block, right??
This is the code. I expect to see the string “Afterward:turkey”, but
why am I getting “Afterward:camel”? |animal| parameter in a block
should be temporary inside the block, right??
No, it isn’t because it was defined outside the block. It’s used in
cases
like
Block parameters actually use assignment semantics, so if a variable
already exists, it gets assigned to. The animal in the pipes is the
same as the animal before the block. If you use a new local variable,
it will come into being just for the block.
Before a hundred-message thread gets spawned, let me add that yes,
it’s going to change in 2.0 I’m actually one of the few people
who like it the way it is, but Matz has said that he considers it a
design mistake and wants to change it.
I may be getting it wrong… but I think the scoping of parameter
variables and other block variables is going to diverge.
That’s why I stick to the status quo - I lost track of this discussion
somewhere. But I trust Matz to do it properly. At least all relevant
arguments seem to have been exchanged.
block should be temporary inside the block, right??
? I think in both cases foo is limited to the block:
I guess I had the impression that what puzzled the OP was that using a
variable as a block parameter (as opposed to just using it in the
block) was trampling the outer variable. Anyway, as you say, all
perspectives have been accounted for (many times, counting the
archives