ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
* [ruby-core:123113] [Ruby Feature#21555] Add support for predicate attribute reader names
@ 2025-08-28 22:56 shan (Shannon Skipper) via ruby-core
  2025-08-29  4:07 ` [ruby-core:123115] " Dan0042 (Daniel DeLorme) via ruby-core
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: shan (Shannon Skipper) via ruby-core @ 2025-08-28 22:56 UTC (permalink / raw)
  To: ruby-core; +Cc: shan (Shannon Skipper)

Issue #21555 has been reported by shan (Shannon Skipper).

----------------------------------------
Feature #21555: Add support for predicate attribute reader names
https://bugs.ruby-lang.org/issues/21555

* Author: shan (Shannon Skipper)
* Status: Open
----------------------------------------
After manually aliasing predicate methods many times, I wanted to propose letting `attr_reader` take predicate method names that correspond to instance variables of the base name without a trailing question mark. https://github.com/ruby/ruby/pull/14391

If the base name method doesn't already exist, a predicate name defines a base name method attribute reader to alias then undefines the base name.

For example, this creates an `enabled?` method that reads `@enabled`:
```ruby
attr_reader :enabled?
```

This feature is only supported for `attr_reader` and `attr`, not `attr_writer` or `attr_accessor`, since setter methods cannot have question marks.

Example:
```ruby
class Example
  attr_reader :valid?, :meaning

  def initialize
    @valid = [true, false].sample
    @meaning = 42
  end
end

Example.new.valid? #=> true
```



-- 
https://bugs.ruby-lang.org/
______________________________________________
 ruby-core mailing list -- ruby-core@ml.ruby-lang.org
 To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
 ruby-core info -- https://ml.ruby-lang.org/mailman3/lists/ruby-core.ml.ruby-lang.org/

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [ruby-core:123115] [Ruby Feature#21555] Add support for predicate attribute reader names
  2025-08-28 22:56 [ruby-core:123113] [Ruby Feature#21555] Add support for predicate attribute reader names shan (Shannon Skipper) via ruby-core
@ 2025-08-29  4:07 ` Dan0042 (Daniel DeLorme) via ruby-core
  2025-08-29  7:16 ` [ruby-core:123117] " byroot (Jean Boussier) via ruby-core
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Dan0042 (Daniel DeLorme) via ruby-core @ 2025-08-29  4:07 UTC (permalink / raw)
  To: ruby-core; +Cc: Dan0042 (Daniel DeLorme)

Issue #21555 has been updated by Dan0042 (Daniel DeLorme).


Also related to #5781 #11167 #12046 #15991 #19708
Popular eh?

----------------------------------------
Feature #21555: Add support for predicate attribute reader names
https://bugs.ruby-lang.org/issues/21555#change-114433

* Author: shan (Shannon Skipper)
* Status: Open
----------------------------------------
After manually aliasing predicate methods many times, I wanted to propose letting `attr_reader` take predicate method names that correspond to instance variables of the base name without a trailing question mark. https://github.com/ruby/ruby/pull/14391

If the base name method doesn't already exist, a predicate name defines a base name method attribute reader to alias then undefines the base name.

For example, this creates an `enabled?` method that reads `@enabled`:
```ruby
attr_reader :enabled?
```

This feature is only supported for `attr_reader` and `attr`, not `attr_writer` or `attr_accessor`, since setter methods cannot have question marks.

Example:
```ruby
class Example
  attr_reader :valid?, :meaning

  def initialize
    @valid = [true, false].sample
    @meaning = 42
  end
end

Example.new.valid? #=> true
```



-- 
https://bugs.ruby-lang.org/
______________________________________________
 ruby-core mailing list -- ruby-core@ml.ruby-lang.org
 To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
 ruby-core info -- https://ml.ruby-lang.org/mailman3/lists/ruby-core.ml.ruby-lang.org/

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [ruby-core:123117] [Ruby Feature#21555] Add support for predicate attribute reader names
  2025-08-28 22:56 [ruby-core:123113] [Ruby Feature#21555] Add support for predicate attribute reader names shan (Shannon Skipper) via ruby-core
  2025-08-29  4:07 ` [ruby-core:123115] " Dan0042 (Daniel DeLorme) via ruby-core
@ 2025-08-29  7:16 ` byroot (Jean Boussier) via ruby-core
  2025-08-29 22:57 ` [ruby-core:123130] " shan (Shannon Skipper) via ruby-core
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: byroot (Jean Boussier) via ruby-core @ 2025-08-29  7:16 UTC (permalink / raw)
  To: ruby-core; +Cc: byroot (Jean Boussier)

Issue #21555 has been updated by byroot (Jean Boussier).


> This feature is only supported for attr_reader and attr, not attr_writer or attr_accessor, since setter methods cannot have question marks.

Using the same logic, `attr_accessor :enabled?` could generate `#enabled?` and `#enabled=` without problem. `attr_writer :enabled?` would be weird though.

----------------------------------------
Feature #21555: Add support for predicate attribute reader names
https://bugs.ruby-lang.org/issues/21555#change-114435

* Author: shan (Shannon Skipper)
* Status: Open
----------------------------------------
After manually aliasing predicate methods many times, I wanted to propose letting `attr_reader` take predicate method names that correspond to instance variables of the base name without a trailing question mark. https://github.com/ruby/ruby/pull/14391

If the base name method doesn't already exist, a predicate name defines a base name method attribute reader to alias then undefines the base name.

For example, this creates an `enabled?` method that reads `@enabled`:
```ruby
attr_reader :enabled?
```

This feature is only supported for `attr_reader` and `attr`, not `attr_writer` or `attr_accessor`, since setter methods cannot have question marks.

Example:
```ruby
class Example
  attr_reader :valid?, :meaning

  def initialize
    @valid = [true, false].sample
    @meaning = 42
  end
end

Example.new.valid? #=> true
```



-- 
https://bugs.ruby-lang.org/
______________________________________________
 ruby-core mailing list -- ruby-core@ml.ruby-lang.org
 To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
 ruby-core info -- https://ml.ruby-lang.org/mailman3/lists/ruby-core.ml.ruby-lang.org/

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [ruby-core:123130] [Ruby Feature#21555] Add support for predicate attribute reader names
  2025-08-28 22:56 [ruby-core:123113] [Ruby Feature#21555] Add support for predicate attribute reader names shan (Shannon Skipper) via ruby-core
  2025-08-29  4:07 ` [ruby-core:123115] " Dan0042 (Daniel DeLorme) via ruby-core
  2025-08-29  7:16 ` [ruby-core:123117] " byroot (Jean Boussier) via ruby-core
@ 2025-08-29 22:57 ` shan (Shannon Skipper) via ruby-core
  2025-09-11  5:21 ` [ruby-core:123215] " matz (Yukihiro Matsumoto) via ruby-core
  2025-09-16 11:50 ` [ruby-core:123260] " Dan0042 (Daniel DeLorme) via ruby-core
  4 siblings, 0 replies; 6+ messages in thread
From: shan (Shannon Skipper) via ruby-core @ 2025-08-29 22:57 UTC (permalink / raw)
  To: ruby-core; +Cc: shan (Shannon Skipper)

Issue #21555 has been updated by shan (Shannon Skipper).


Dan0042 (Daniel DeLorme) wrote in #note-2:
> Also related to #5781 #11167 #12046 #15991 #19708
> Popular eh?

Wow! There's already an open ticket for this exact issue even. I apologize for not properly searching before filing. I should have just added a PR link there in retrospect.

byroot (Jean Boussier) wrote in #note-3:
> > This feature is only supported for attr_reader and attr, not attr_writer or attr_accessor, since setter methods cannot have question marks.
> 
> Using the same logic, `attr_accessor :enabled?` could generate `#enabled?` and `#enabled=` without problem. `attr_writer :enabled?` would be weird though.

I was thinking of `attr_writer :enabled?` being weird and dismissed `attr_accessor :enabled?`. I didn't think of the case where you want `attr_reader :enabled?` and `attr_writer :enabled` without `attr_writer :enabled`. I wouldn't mind doing an `attr_reader :enabled?` with `attr_writer :enabled` but agree `attr_accessor :enabled?` makes sense based on the pattern.

----------------------------------------
Feature #21555: Add support for predicate attribute reader names
https://bugs.ruby-lang.org/issues/21555#change-114457

* Author: shan (Shannon Skipper)
* Status: Open
----------------------------------------
After manually aliasing predicate methods many times, I wanted to propose letting `attr_reader` take predicate method names that correspond to instance variables of the base name without a trailing question mark. https://github.com/ruby/ruby/pull/14391

If the base name method doesn't already exist, a predicate name defines a base name method attribute reader to alias then undefines the base name.

For example, this creates an `enabled?` method that reads `@enabled`:
```ruby
attr_reader :enabled?
```

This feature is only supported for `attr_reader` and `attr`, not `attr_writer` or `attr_accessor`, since setter methods cannot have question marks.

Example:
```ruby
class Example
  attr_reader :valid?, :meaning

  def initialize
    @valid = [true, false].sample
    @meaning = 42
  end
end

Example.new.valid? #=> true
```



-- 
https://bugs.ruby-lang.org/
______________________________________________
 ruby-core mailing list -- ruby-core@ml.ruby-lang.org
 To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
 ruby-core info -- https://ml.ruby-lang.org/mailman3/lists/ruby-core.ml.ruby-lang.org/

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [ruby-core:123215] [Ruby Feature#21555] Add support for predicate attribute reader names
  2025-08-28 22:56 [ruby-core:123113] [Ruby Feature#21555] Add support for predicate attribute reader names shan (Shannon Skipper) via ruby-core
                   ` (2 preceding siblings ...)
  2025-08-29 22:57 ` [ruby-core:123130] " shan (Shannon Skipper) via ruby-core
@ 2025-09-11  5:21 ` matz (Yukihiro Matsumoto) via ruby-core
  2025-09-16 11:50 ` [ruby-core:123260] " Dan0042 (Daniel DeLorme) via ruby-core
  4 siblings, 0 replies; 6+ messages in thread
From: matz (Yukihiro Matsumoto) via ruby-core @ 2025-09-11  5:21 UTC (permalink / raw)
  To: ruby-core; +Cc: matz (Yukihiro Matsumoto)

Issue #21555 has been updated by matz (Yukihiro Matsumoto).

Status changed from Open to Rejected

I still ask you to define `def valid? = @valid` manually. It is not much worse than `attr_reader :valid?`.

Matz.


----------------------------------------
Feature #21555: Add support for predicate attribute reader names
https://bugs.ruby-lang.org/issues/21555#change-114545

* Author: shan (Shannon Skipper)
* Status: Rejected
----------------------------------------
After manually aliasing predicate methods many times, I wanted to propose letting `attr_reader` take predicate method names that correspond to instance variables of the base name without a trailing question mark. https://github.com/ruby/ruby/pull/14391

If the base name method doesn't already exist, a predicate name defines a base name method attribute reader to alias then undefines the base name.

For example, this creates an `enabled?` method that reads `@enabled`:
```ruby
attr_reader :enabled?
```

This feature is only supported for `attr_reader` and `attr`, not `attr_writer` or `attr_accessor`, since setter methods cannot have question marks.

Example:
```ruby
class Example
  attr_reader :valid?, :meaning

  def initialize
    @valid = [true, false].sample
    @meaning = 42
  end
end

Example.new.valid? #=> true
```



-- 
https://bugs.ruby-lang.org/
______________________________________________
 ruby-core mailing list -- ruby-core@ml.ruby-lang.org
 To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
 ruby-core info -- https://ml.ruby-lang.org/mailman3/lists/ruby-core.ml.ruby-lang.org/

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [ruby-core:123260] [Ruby Feature#21555] Add support for predicate attribute reader names
  2025-08-28 22:56 [ruby-core:123113] [Ruby Feature#21555] Add support for predicate attribute reader names shan (Shannon Skipper) via ruby-core
                   ` (3 preceding siblings ...)
  2025-09-11  5:21 ` [ruby-core:123215] " matz (Yukihiro Matsumoto) via ruby-core
@ 2025-09-16 11:50 ` Dan0042 (Daniel DeLorme) via ruby-core
  4 siblings, 0 replies; 6+ messages in thread
From: Dan0042 (Daniel DeLorme) via ruby-core @ 2025-09-16 11:50 UTC (permalink / raw)
  To: ruby-core; +Cc: Dan0042 (Daniel DeLorme)

Issue #21555 has been updated by Dan0042 (Daniel DeLorme).


I think Matz's position is clear and will not change, so what about closing the related tickets that are still open?

----------------------------------------
Feature #21555: Add support for predicate attribute reader names
https://bugs.ruby-lang.org/issues/21555#change-114626

* Author: shan (Shannon Skipper)
* Status: Rejected
----------------------------------------
After manually aliasing predicate methods many times, I wanted to propose letting `attr_reader` take predicate method names that correspond to instance variables of the base name without a trailing question mark. https://github.com/ruby/ruby/pull/14391

If the base name method doesn't already exist, a predicate name defines a base name method attribute reader to alias then undefines the base name.

For example, this creates an `enabled?` method that reads `@enabled`:
```ruby
attr_reader :enabled?
```

This feature is only supported for `attr_reader` and `attr`, not `attr_writer` or `attr_accessor`, since setter methods cannot have question marks.

Example:
```ruby
class Example
  attr_reader :valid?, :meaning

  def initialize
    @valid = [true, false].sample
    @meaning = 42
  end
end

Example.new.valid? #=> true
```



-- 
https://bugs.ruby-lang.org/
______________________________________________
 ruby-core mailing list -- ruby-core@ml.ruby-lang.org
 To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
 ruby-core info -- https://ml.ruby-lang.org/mailman3/lists/ruby-core.ml.ruby-lang.org/

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2025-09-16 11:52 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-08-28 22:56 [ruby-core:123113] [Ruby Feature#21555] Add support for predicate attribute reader names shan (Shannon Skipper) via ruby-core
2025-08-29  4:07 ` [ruby-core:123115] " Dan0042 (Daniel DeLorme) via ruby-core
2025-08-29  7:16 ` [ruby-core:123117] " byroot (Jean Boussier) via ruby-core
2025-08-29 22:57 ` [ruby-core:123130] " shan (Shannon Skipper) via ruby-core
2025-09-11  5:21 ` [ruby-core:123215] " matz (Yukihiro Matsumoto) via ruby-core
2025-09-16 11:50 ` [ruby-core:123260] " Dan0042 (Daniel DeLorme) via ruby-core

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).