From: Peter Hickman Date: 2013-03-11T19:20:47+09:00 Subject: Re: Confusion with block local variable declaration with block variable declaration within the pipe `|` --047d7b621f2a959e6104d7a386f3 Content-Type: text/plain; charset=ISO-8859-1 Your first example does not work for me in any version of Ruby. But this does a = "hello world".split(//).each{ |x,newstr = Array.new() | newstr = x.capitalize;puts newstr } Note the use of a , rather than a ; between the | ... | Also why are you assigning an Array to newstr? It makes absolutely no sense as x.capitalize will simply replace it with a string. The use of , rather than ; holds for all your examples. This has nothing to do with creating local variables and everything to do with writing bad code. --047d7b621f2a959e6104d7a386f3 Content-Type: text/html; charset=ISO-8859-1
Your first example does not work for me in any version of Ruby. But this does

a = "hello world".split(//).each{ |x,newstr = Array.new() | newstr = x.capitalize;puts newstr }

Note the use of a , rather than a ; between the | ... |
Also why are you assigning an Array to newstr? It makes absolutely no sense as x.capitalize will simply replace it with a string.

The use of , rather than ; holds for all your examples.

This has nothing to do with creating local variables and everything to do with writing bad code.
--047d7b621f2a959e6104d7a386f3--