From: eregontp@... Date: 2016-07-19T09:46:41+00:00 Subject: [ruby-core:76443] [Ruby trunk Feature#8563] Instance variable arguments Issue #8563 has been updated by Benoit Daloze. Anonymous wrote: > @Matz: If `define_attr_initialize` is an option, then there is a question of named / ordered qualifier, either as: > > ~~~Ruby > define_attr_initialize :foo, :bar, as: :named > define_attr_initialize :baz, :quux, as: :ordered > ~~~ > You could have simply: ~~~Ruby define_attr_initialize :baz, :quux, foo: nil, bar: nil ~~~ But this starts to look much like a macro to me. One problem with the proposed `define_attr_initialize` is once some extra behavior needs to be added to `initialize`, there is no choice but to desugar everything (write ivar assignments manually). The original proposition does not have this issue. IMHO many constructors usually need some custom behavior after some time, and so paying the "cost" upfront of doing manual assignments is worth it in many cases. ---------------------------------------- Feature #8563: Instance variable arguments https://bugs.ruby-lang.org/issues/8563#change-59690 * Author: Tsuyoshi Sawada * Status: Assigned * Priority: Normal * Assignee: Yukihiro Matsumoto ---------------------------------------- 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: