From: dblack@... Date: 2006-03-22T23:51:39+09:00 Subject: Re: questions/suggestions from a Ruby newbie Hi -- On Wed, 22 Mar 2006, Diego.Virasoro@gmail.com wrote: > Hi, > first of all let me say I really really like Ruby, and I look forward > to use it in my projects. Cool! > Here it's a list of my current problems: > > -Is there a way to have multidimentional arrays in Ruby? Ie something > like variable[3][2]? One could use arrays of arrays but it does not > look quite as clear when reading the code. How about: variable[3][2] ? :-) As long as both variable and variable[3] respond to "[]", you should be OK. (They don't even have to be arrays.) > -I read the discussion about the use of the "end" keyword, and possible > alternatives. Instead of trying to change that, I think it would be > easier and more consistent with Ruby's syntax to change the way if, > unless and while work so that they take a block as an argument. Then > if/while would work more consistently as the other methods, and in > particular the iterators: in both cases you could delimit the code with > a keyword like "end" or the curly bracket. For example these would be > all acceptable: > > if(x==y) do > #code > end > > if(x==y) { > #code > } > > (the first one would pretty much look like it already does, and one > could decide that "do" can be omitted to make it compatible with > existing code.) That starts to tie the language in knots. For one thing, if can take a method with a block: if x { }; y end I think things would start to get much too messy, especially with an optional "do". > In other words it would look just like for iterators (more consistent > Ruby) and at the same time make happy those that want brackets instead > of keywords to delimit if/while/unless: two birds with one stone. I don't think people wanting brackets, as a general matter, is a "bird" in the first place :-) Consistency isn't really an issue here either, since if isn't a method; and if if were a method, but the "do" were optional, it wouldn't be consistent anyway. In other words, if is a syntactic construct, and code blocks are also syntactic constructs; but there's no inherent reason why they should be unified. (I know Smalltalk and maybe other languages handle conditionals as methods, but I don't think it would mesh well with Ruby.) I would recommend living with these constructs for a while, on their own terms. I'm reasonably certain that it will cease to feel like something is missing or wrong. > Thank you very much. Anyway Ruby keeps being a great language and I > really love it (though I have not use it much yet). It's great, isn't it? :-) David -- David A. Black (dblack@wobblini.net) Ruby Power and Light, LLC (http://www.rubypowerandlight.com) "Ruby for Rails" chapters now available from Manning Early Access Program! http://www.manning.com/books/black