Skip to content

Ruby 3.0 and support for chaining private with attr_* methods #43

@radarek

Description

@radarek

Hello.

I'm not familiar with this library (I only scanned the README) but I think you might be interested in the fact, that as of Ruby 3.0, it supports chaining private call with methods that defines attribute accessors (I implemented this, see https://bugs.ruby-lang.org/issues/17314). Having this feature, it is unnecessary to have method like attr_private and I think it would be good idea to mention that in the README file.

Here is example usage.

class Foo
  private attr_accessor :foo, :bar
  # this the same as:
  attr_accessor :foo, :bar
  private :foo, :foo=, :bar, :bar=
end

This works with any method which returns defined method name (symbol) or defined method names (array of symbols). As of Ruby 3.0 attr_{reader,writer,accessor} returns array of defined method names:

class Foo
  p attr_accessor :foo, :bar #=> [:foo, :foo=, :bar, :bar=]
end

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions