From: William Djaja Tjokroaminata Date: 2002-09-27T08:58:37+09:00 Subject: Re: Ruby - common pitfalls? Hi, I just created this list starting one hour ago. Not to create lengthy discussions, please send any comment directly to me via e-mail. Thanks. Regards, Bill Things That Newcomers to Ruby Should Know ========================================= 1) Use "ruby -w" instead of simply "ruby" to get helpful warnings. 2) The String#[Fixnum] method does not return the "character" (which is a string of length one) at the Fixnum position, but instead the character code at the position (however, this may change in the future). Currently, to get the character, use String#[Fixnum,1] instead. 3) Be aware of the lexical scoping interaction between local variables and block local variables. If a local variable is already defined before the block, then the block will use (and quite possibly) modify the local variable; in this case the block does not introduce a new scope. 4) In Ruby, there are two sets of logical operators: [!, &&, ||] and [not, and, or]. [!, &&, ||]'s precedence is higher than the assignments (=, %=, ~=, /=, etc.) while [not, and, or]'s precedence is lower. Also note that while &&'s precedence is higher than ||'s, the and's precedence is the same as the or's. 5) In the case statement case obj when obj1 .... it is the "===" method which is invoked, not the "==" method. Also, the order is "obj1 === obj" and not "obj === obj1". 6) Array.new (2, Hash.new) returns an array with two elements referencing the same, indentical hash, and not two independent hashes. 7) After reading data from a file and putting them into variables, the data type is really String. To convert them into numbers, use the "to_i" or "to_f" methods. If you use the "+" operator to add the "numbers" without calling the conversion methods, for example, you will simply concatenate the strings. -----