Issue #8563 has been updated by headius (Charles Nutter).


Worth pointing out that blocks used to support this:

1.times { |@foo| ... }

Basically, it supported anything you can have on the LHS of a normal assignment:

foo.bar { |a, @b, @@c, D, e.val, f[0]| ... } 

I believe it was taken out in 1.9 because it made argument processing a lot more complicated, but then 1.9 added the ability to do multiple-assignment grouping, default values, and other masgn features to all argument lists anyway. It doesn't seem like it would be too terribly complicated to add this back in, but I wonder about the OTHER reasons that non-local variable assignment was removed from argument lists in the first place.

As for the utility of the feature, I'd like it but I can live without it. It does seem rather un-Ruby to have to declare locals and do the assignment when all you want is to set an instance variable...especially when you have a lot of instance variables.

Note also that for a trivial initialize, where the only line is a multiple-assignment to set instance variables, every initialize call pays the cost of creating an Array for the masgn (see my rejected request in https://bugs.ruby-lang.org/issues/6668).

def initialize(a, b, c, d, e)
  @a, @b, @c, @d, @e = a, b, c, d, e # creates transient array every time
end
----------------------------------------
Feature #8563: Instance variable arguments
https://bugs.ruby-lang.org/issues/8563#change-40093

Author: sawa (Tsuyoshi Sawada)
Status: Assigned
Priority: Normal
Assignee: matz (Yukihiro Matsumoto)
Category: syntax
Target version: Next Major


=begin
Often times, people want to assign given arguments to instance variables, especially inside the method `initialize`:

    def initialize foo, bar, buz
      @foo, @bar, @buz = foo, bar, buz
      ...
    end

I propose to let method definition take instance variables as arguments so that:

    def initialize @foo, @bar, @buz
      ...
    end

would be equivalent as above.
=end



-- 
http://bugs.ruby-lang.org/