From: dblack@... Date: 2006-05-01T06:28:50+09:00 Subject: Re: how to use curly brackets vs. 'end' in Ruby Hi -- On Sat, 29 Apr 2006, carlo wrote: > i dislike the use of 'end' (just about the only think i *don't* like in > ruby). so, since everybody is saying that this is just a matter of > taste, why won't this work: > > class Hello > { > attr_reader :msg The point is that the {}/do/end distinction is largely (not entirely) a matter of taste, not that you can put curly braces anywhere in Ruby code :-) > def initialize > { > @msg = "Hello, World" > } > } > h = Hello.new > puts h.msg > print "Press RETURN" > $stdin.gets > > Or what about this: > > def fib(n) > { > if (n<2) > { > n > } > else > { > fib(n-2)+fib(n-1) > } > } > print(fib(20), "\n"); Don't forget puts :-) puts fib(2) > in other words, i'm more comfortable with {} coming from C,C++, & C# > so I've always found it's much easier, when you're writing Ruby code, to "come from" Ruby. That way, you don't have to fight the language, or convince yourself to be disappointed because it doesn't have the same syntax as other languages. You free yourself to enjoy it a lot more. Also, remember that Ruby is a language, not a vague, unformulated idea for a language. It's not Ruby's responsibility to pepper the code with curly braces because they appear a lot in C, any more than it is C's responsibility to stop using them because they appear less in Ruby. David -- David A. Black (dblack@wobblini.net) Ruby Power and Light, LLC (http://www.rubypowerandlight.com) "Ruby for Rails" PDF now on sale! http://www.manning.com/black Paper version coming in early May!