[Discussion about += etc. snipped as it’s deallt with by other posts.]
x, y, z = , ,
x, y, z << nil # [nil], [nil], [nil]
x, y, z == [nil] # [true, true, true]
(x, y, z).method(arg) # hmm…
Well, = and += are both considered
assignment operations. That’s enough
rationale (for me) to draw the line
with +=, -=, and the others.
Truthfully, though, some of your constructs
above look almost tempting.
I would not go for ==, but for << and
.method I might be persuaded.
Hal
The “almost tempting” options are only a “map” away (I prefer :map over
:collect, but don’t see much code using it…).
Sugar:
x, y, z = , ,
x, y, z << nil # [nil, nil, nil]
[x, y, z].map { |arr| arr << nil } # Can also use :each
Sugar:
x, y, z == nil # [true, true, true]
[x, y, z].map { |arr| arr == [nil] }
Sugar:
(x, y, z).method(arg) # hmm…
[x, y, z].map { |obj| obj.method(arg) }
EOF
Now, I love the “map” method, but sometimes its use is more verbose than it
could be. It “would be nice” if one could do the following things:
names = %w(john mary adam jacky)
names.map { capitalize } # → [“John”, “Mary”, “Adam”, “Jacky”]
x, y, z = , ,
[x, y, z].map { $_ << [nil] } # → [nil, nil, nil]
[x, y, z].map { $_ == [nil] } # → [true, true, true]
Obviously there are limits, but I think that there could be a way to do this
without exposing the language to ambiguity, contradiction, slothfulness or
confused identity (!) The “capitalize” example may be stretching it a bit
far, but surely the other two examples are good?
What do people think?
–Gavin
···
----- Original Message -----
From: “Hal E. Fulton” hal9000@hypermetrics.com