Feature #14132
closedModule#attr{|_reader|_writer} should be public
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.
Updated by marcandre (Marc-Andre Lafortune) about 7 years ago
- Related to Feature #6539: public and private for core methods added
Updated by marcandre (Marc-Andre Lafortune) about 7 years ago
- Related to Feature #14133: Module#{define|alias|undef}_method should be made public added
Updated by marcandre (Marc-Andre Lafortune) about 7 years ago
- Status changed from Open to Closed