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.