From: "Bartosz DziewoƄski" Date: 2011-12-09T20:25:00+09:00 Subject: Re: Confusing results from string multiplication Just a note that this might happen not only with multiplication vs splat operator. Division vs regex definition can give similar troubles. (Please note that the parsing is always deterministic, and the interpreter will try its best guess, using spacing as hints. In Perl, a code like the one below could parse differently depending on the number of arguments the function takes.) irb(main):001:0> def foo; 5; end irb(main):002:0> foo/2 #/ => 2 irb(main):003:0> foo / 2 #/ => 2 irb(main):004:0> foo /2 #/ ArgumentError: wrong number of arguments (1 for 0) from (irb):2:in `foo' from (irb):4 from C:/Ruby192/bin/irb:12:in `
' Or with bitwise AND vs the unary to_proc operator: irb(main):015:0> foo & 6 => 4 irb(main):016:0> foo &6 TypeError: wrong argument type Fixnum (expected Proc) from (irb):16 from C:/Ruby192/bin/irb:12:in `
' Just code reasonably: when you want to use something as a binary operator, space equally on its both sides; when you want unary operator, only space to the left. (Or just use the damn parentheses.) -- Matma Rex