From: Kenichi Komiya Date: 2001-01-06T16:37:21+09:00 Subject: [ruby-talk:8730] Re: Braces and begin/end Hi, From: Kevin Smith > I've been trying to develop my own Ruby style. > Since I came from a C++ world, I realized that > the curly braces (with dramatically different > meaning) would be confusing to me. So I don't use > them. Ever. I always use do/end, formatted like > this: Maybe you better take a closer look at the difference before deciding that firmly :-) According to the reference manual for Ruby 1.4, it is boiled down to: - Braces has stronger precedence. - Braces introduce the nested local scopes. Let me talk about the former (as later point is well demonstrated in the manual). The document says: foobar a, b do .. end # foobar will be called with the block. foobar a, b { .. } # b will be called with the block. This, in turn, forms a syntax rule that "do .. end" can not be followed by another method call. (I am not sure if this is an inevitable consequence of above precedence rule or just specific to current implementation, though.) For example, Ruby allow you to write something like bellow. # case-insensitive sort ["Foo", "bAr", "zoT"].collect{ |str| [str.downcase, str] }.sort.collect{ |pair| pair[1] } # => ["bAr", "Foo", "zoT"] But you can not simply replace { .. } with do .. end here (coz, the call of sort is not allowed after do .. end). It is, of course, an option that never ever using chain like above. But I personally feel like being more flexible :) Minero Aoki has an interesting page discussing things like this at length (Japanese only). http://www1.u-netsurf.ne.jp/~brew/mine/ja/ruby/style.html Does anyone do the similar thing in English? Regards, Kenichi Komiya.