Project

General

Profile

Actions

Feature #6470

closed

Make attr_accessor return the list of generated method

Added by rupert (Robert Pankowecki) over 12 years ago. Updated over 3 years ago.

Status:
Closed
Target version:
-
[ruby-core:45144]

Description

attr_accesor currently returns nil. It would be more helpful if it return list of generated methods so that it can become an argument to other methods like :private or :protected. That way private accessors can still be defined at top of the class and be private without changing the visibility of next methods.

class Something
  private *attr_accessor :user, :action # IMHO This is nice
  # private attr_accessor :user, :action # <-- would be even better if :private method accepted arrays

  def initialize(user, action)
    self.user   = user
    self.action = action
  end

  def public_method
    user.do_something(action)
  end
end

VS

class Something
  private; attr_accessor :user, :action; public # IMHO Hack!!

  def initialize(user, action)
    self.user   = user
    self.action = action
  end

  def public_method
    user.do_something(action)
  end
end

VS

class Something
  def initialize(user, action)
    self.user   = user
    self.action = action
  end

  def public_method
    user.do_something(action)
  end

  private
  attr_accessor :user, :action # IMHO Does not look nice at bottom of the class definition
end

Related issues 4 (1 open3 closed)

Related to Ruby master - Feature #11539: Support explicit declaration of volatile instance variablesOpenActions
Related to Ruby master - Feature #11541: Let attr_accessor, _reader & _writer return symbols of the defined methodsClosedActions
Related to Ruby master - Feature #17314: Provide a way to declare visibility of attributes defined by attr* methods in a single expressionClosedActions
Is duplicate of Ruby master - Feature #6198: public/protected/private with attr_*Rejectedmatz (Yukihiro Matsumoto)Actions
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0