From: Love U Ruby Date: 2013-03-11T18:57:58+09:00 Subject: Confusion with block local variable declaration with block variable declaration within the pipe `|` Why are we not allowed to create local variables or new object with block variables? The below are allowed : a = "hello world".split(//).each{ |x;newstr = Array.new() | newstr = x.capitalize;puts newstr } H E L L O W O R L D => ["h", "e", "l", "l", "o", " ", "w", "o", "r", "l", "d"] and [1,2,3].each {|num|temp =0 ; temp = num ; print temp} #123=> [1, 2, 3] For what reasons the below are not allowed? [1,2,3].each {|num;temp =0| temp = num;print temp} #SyntaxError: (irb):5: syntax error, unexpected '=', expecting '|' #[1,2,3].each {|num;temp =0| temp = num;print} ^ #(irb):5: syntax error, unexpected '}', expecting $end # from C:/Ruby193/bin/irb:12:in `
' and a = "hello world".split(//).each{ |x;newstr = Array.new() | newstr = x.capitalize;puts newstr } -- Posted via http://www.ruby-forum.com/.