Hal Fulton wrote in post #1114777:
>
> Note that this wouldn't be a method call (like alias_method) but
> a keyword (like alias) unless "binding of caller" was permitted...
> which is another thing I've wanted but I suppose will never
> happen.
>
> Comments, questions, projectiles?
Yeah, I agree with Robert, there's no need to dynamically create local
variables, just use a hash (dynamically created keys are fine). And my
initial gut response is: if you're writing that many variables on the
left hand side of an assignment, with a single array on the right,
there's probably something wrong with the architecture.
That situation frequently occurs when reading data e.g. from CSV files. If
the file has that many columns it makes sense to have local variables for
them to ease handling. OTOH then you probably use something like
CSV.foreach "a.csv" do |foo, bar, baz, alpha, beta|
puts "foo is #{foo}"
end
Or one defines a Struct and puts values in there instead of having them in
an Array.
My other counter-proposal is: hit enter. If the line is too long,
develop a syntactic signature for the pattern. For example:
foo, bar, baz, alpha, beta,
gamma, fred, bill, joey = *values
(i.e. lining up the rightmost column, so it's clear that all wrapped
lines lead to the single assignment operator). Still not great, but at
least the line isn't absurdly long, and you don't have to scan as far to
see the '='
I like that approach.
Finally, as a bike-shedding nit-pick: if it were a keyword, convention
suggests there'd be no comma; and I think putting the destinations on
the right is a bit confusing. So if I had to choose, I'd go for:
assign %I[a b c] values
But again, that's a big "if", and all in all I'm not too keen on the
idea of dynamically creating local variables.
I forgot to mention: I do not see the original issue as such a big one, so
my general bias would be against going through some hoops just to avoid
lengthy left hand sides. I don't have them that often and if I have it
does not bother me that much.
Kind regards
robert
···
On Tue, Jul 9, 2013 at 1:14 AM, Matthew Kerwin <lists@ruby-forum.com> wrote:
--
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/