From: "Peña, Botp" Date: 2007-10-30T19:19:57+09:00 Subject: Re: what is the difference between two block? From: Arul hari [mailto:hariharan.spc@rediffmail.com] # I wan to know the difference,I feel soething is there,but i # am not able to findout the answers for this. there is difference, but not much > def f a,b > yield a,b > end precedence issue: > f 1,2 {|x,y| p x,y} SyntaxError: compile error (irb):33: syntax error, unexpected '{', expecting $end f 1,2 {|x,y| p x,y} ^ > f 1,2 do|x,y| p x,y end 1 2 as always, it is safe by enclosing parameters w parens irb(main):035:0> f(1,2) {|x,y| p x,y} 1 2 irb(main):036:0> f(1,2) do|x,y| p x,y end 1 2 also, one-liner chain fans sees do-end as noisy and sensitive to spacing (since do-ends are keywords) irb(main):037:0> [1,2,3].map{|x| 2*x}.map{|x|x+1} => [3, 5, 7] irb(main):038:0> [1,2,3].map do|x| 2*x end.map do |x|x+1 end => [3, 5, 7] irb(main):039:0> [1,2,3].mapdo|x| 2*x end.map do |x|x+1 end SyntaxError: compile error (irb):39: syntax error, unexpected kEND, expecting $end [1,2,3].mapdo|x| 2*x end.map do |x|x+1 end ^ nonetheless, i like both. i particularly like do-end since i like typing fast without using shift. but if you have editors like textmate or similar, no need :) kind regards -botp