Peña, Botp
2/16/2007 5:19:00 AM
fr: sur max [mailto:sur.max@gmail.com] :
# b = [*a,6] # => [9,5,6] ----- false, compile error
# b = *a,6 # => [9,5,6] ----- false, compile error
pls be careful. "*" op will splat. so here ruby is just telling/policing you not too.
I always treat splat op as a black hole. this way i make less mistakes.
eg
so this is allowed,
irb(main):050:0> b,*a=1,2,3,4
=> [1, 2, 3, 4]
irb(main):052:0> a
=> [2, 3, 4]
this one is not,
irb(main):053:0> b,*a,c=1,2,3,4
SyntaxError: compile error
(irb):53: syntax error, unexpected ',', expecting '=' b,*a,c=1,2,3,4
irb(main):054:0>
ruby, is telling me that "*a" is a blackhole. The c does "not matter".
so is this one,
irb(main):056:0> *a
SyntaxError: compile error
(irb):56: syntax error, unexpected '\n', expecting '='
that's a blackhole without a hole or opening. feed it :)
again, another stupid blackhole reasoning.
nonetheless, splat is a very sweet yet too powerful operator. I feel that splat op digress oo-ness. But i believe it's not oo for oo's sake. It's solving problems and discovering brilliant solutions. Ruby does it w ease and fun. Sometimes, i feel ruby will trend toward object and method unification, wherein objects can be methods and vice versa. arggh, like matter <==> energy. maybe, a superproc or superlamdba in the future... i'll stop now :)
drive w caution, (black)holes ahead.
sorry for the long post fr a nuby.
kind regards -botp