C
Chih-Chao Lam
Apologies for a newbie ruby question:
I know an asterisk can precede a parameter in the argument list of a
method definition as in
def varargs(arg1, *rest)
But looking at the source code of Hpricot, I see that you can precede
an asterisk before any variable. Is there a formal definition for the
use of this operator?
irb(main):001:0> *d = 3
=> [3]
irb(main):002:0> d
=> [3]
irb(main):003:0> d == [*d]
=> true
irb(main):004:0> *d
SyntaxError: compile error
(irb):4: parse error, unexpected '\n', expecting '='
from (irb):4
Thanks,
chao
I know an asterisk can precede a parameter in the argument list of a
method definition as in
def varargs(arg1, *rest)
But looking at the source code of Hpricot, I see that you can precede
an asterisk before any variable. Is there a formal definition for the
use of this operator?
irb(main):001:0> *d = 3
=> [3]
irb(main):002:0> d
=> [3]
irb(main):003:0> d == [*d]
=> true
irb(main):004:0> *d
SyntaxError: compile error
(irb):4: parse error, unexpected '\n', expecting '='
from (irb):4
Thanks,
chao