From: Love U Ruby Date: 2013-03-11T19:37:31+09:00 Subject: Re: Confusion with block local variable declaration with block variable declaration within the pipe Peter Hickman wrote in post #1101060: > Again why you assigning to temp and when you immediately overwrite it? The below also doesn't work. >> [1,2,3].each {|num;temp =0| print temp} SyntaxError: (irb):7: syntax error, unexpected '=', expecting '|' [1,2,3].each {|num;temp =0| print temp} ^ (irb):7: syntax error, unexpected tIDENTIFIER, expecting keyword_do or '{' or '( ' [1,2,3].each {|num;temp =0| print temp} ^ from C:/Ruby193/bin/irb:12:in `
' When we write the method block as below, its work. >> def talk(x,y=1) >> p "X = #{x}" >> p "Y = #{y}" >> end => nil >> talk(5) "X = 5" "Y = 1" => "Y = 1" >> talk(5,3) "X = 5" "Y = 3" => "Y = 3" The same way I also tried to put the default value to `temp` as [1,2,3].each {|num;temp =0| temp = num ; print temp} -- Posted via http://www.ruby-forum.com/.