From: ko1@... Date: 2017-11-29T06:27:47+00:00 Subject: [ruby-core:83944] [Ruby trunk Feature#8563] Instance variable arguments Issue #8563 has been updated by ko1 (Koichi Sasada). Oops. ``` class Binding def set_attributes(attrs = self.eval('method(__method__).parameters.map{|t, v| v}')) attrs.each{|attr| self.receiver.instance_variable_set(:"@#{attr}", self.local_variable_get(attr)) } end end class C def initialize a, b x = y = nil binding.set_attributes end end p C.new(1, 2) #=> # ``` ---------------------------------------- Feature #8563: Instance variable arguments https://bugs.ruby-lang.org/issues/8563#change-68005 * Author: sawa (Tsuyoshi Sawada) * Status: Rejected * Priority: Normal * Assignee: matz (Yukihiro Matsumoto) * Target version: ---------------------------------------- Often times, people want to assign given arguments to instance variables, especially inside the method `initialize`: ~~~Ruby 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: ~~~Ruby def initialize @foo, @bar, @buz ... end ~~~ would be equivalent as above. -- https://bugs.ruby-lang.org/ Unsubscribe: