Project

General

Profile

Actions

Feature #14132

closed

Module#attr{|_reader|_writer} should be public

Added by marcandre (Marc-Andre Lafortune) over 6 years ago. Updated over 6 years ago.

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

Description

Modules and classes can be reopened and changed (unless frozen).

This is used in many meta programming techniques.

Currently, attr_accessor, attr_writer and attr_reader are private, so we need to either do a class_eval, reopen the class somehow, or resort to :send

As I previously stated in #6539, I feel that the use of send should be reserved for incorrect usage of actually private methods that might change of interface or aren't meant to be called this way (e.g. respond_to_missing?)

Matz has stated before that "class/module operations should be done in the scope.". Nevertheless, common usage shows that there are many cases where Rubyists prefer using a single line for this, even if it means having to call send.

Here are 15k+ examples of send :attr_accessor in the wild:
https://github.com/search?utf8=%E2%9C%93&q=language%3Aruby+%22send+%3Aattr_accessor%22&type=Code
15k+ examples of send :attr_writer in the wild:
https://github.com/search?utf8=%E2%9C%93&q=language%3Aruby+%22send+%3Aattr_writer%22&type=Code
15k+ examples of send :attr_reader in the wild:
https://github.com/search?utf8=%E2%9C%93&q=language%3Aruby+%22send+%3Aattr_reader%22&type=Code

Please make consider making :attr, :attr_accessor, :attr_writer and :attr_reader public.


Related issues 2 (0 open2 closed)

Related to Ruby master - Feature #6539: public and private for core methodsClosednobu (Nobuyoshi Nakada)Actions
Related to Ruby master - Feature #14133: Module#{define|alias|undef}_method should be made publicClosedmatz (Yukihiro Matsumoto)Actions
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0