Issue #8564 has been updated by phluid61 (Matthew Kerwin).


=begin
matz (Yukihiro Matsumoto) wrote:
 > We need to clarify how this intervene with #initialize.  Any opinion?
 > 
 > Matz

My suggestion is that it take effect before any explicit initialize method.

Examples:

 class A
   attr_accessor foo: 3
   def initialize
     p @foo if defined? @foo
     @foo = 4
   end
 end
 p A.new.foo #=> prints 3, then 4

 class B0
   attr_accessor foo: 3
 end
 class B1 < B0
   def initialize
     p @foo if defined? @foo
     @foo = 4
   end
 end
 p B1.new.foo #=> prints 3, then 4

 class C0
   def initialize
     p @foo if defined? @foo
     @foo = 4
   end
 end
 class C1 < C0
   attr_accessor foo: 3
 end
 p C1.new.foo #=> prints 3, then 4
=end

----------------------------------------
Feature #8564: Extend Module#attr... methods
https://bugs.ruby-lang.org/issues/8564#change-40182

Author: boris_stitnicky (Boris Stitnicky)
Status: Open
Priority: Normal
Assignee: 
Category: 
Target version: 


Extend #attr_reader, #attr_writer, #attr_accessor syntax to accept default values, such as:

    attr_reader foo: 42, bar: 43

Possibility of closures evaluated at initialization time might also be considered:

    attr_reader baz: -> { Time.now }, quux: 42

    


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