[ruby-core:114295] [Ruby master Bug#19786] Data::define() does not work as documented

Issue #19786 has been reported by thyresias (Thierry Lambert). ---------------------------------------- Bug #19786: Data::define() does not work as documented https://bugs.ruby-lang.org/issues/19786 * Author: thyresias (Thierry Lambert) * Status: Open * Priority: Normal * ruby -v: ruby 3.2.2 (2023-03-30 revision e51014f9c0) [x64-mingw-ucrt] * Backport: 3.0: UNKNOWN, 3.1: UNKNOWN, 3.2: UNKNOWN ---------------------------------------- Not sure if this is a bug or a feature. RDoc documentation for Data::define:
define(name, *symbols) → class define(*symbols) → class
Defines a new Data class. If the first argument is a string, the class is stored in Data::<name> constant.
```ruby M1 = Data.define('Measure', :amount, :unit) p M1 #=> M1 p M1.members #=> [:Measure, :amount, :unit] S1 = Struct.new('Measure', :amount, :unit) p S1 #=> Struct::Measure p S1.members #=> [:amount, :unit] ``` Unlike `Struct.new`, `Data.define` does not accept a name as first argument: it converts it to a symbol, and therefore a member. There is no trace of `Data::Measure` in the example above, while we do have `Struct::Measure`. -- https://bugs.ruby-lang.org/

Issue #19786 has been updated by zverok (Victor Shepelev). It's a documentation bug :( The first implementations of `Data` had this feature, but then Matz said it is not necessary (it is considered a legacy in Struct anyway), and I removed the feature but probably forgot to adjust the comments. Already fixed in master: https://docs.ruby-lang.org/en/master/Data.html#method-c-define ---------------------------------------- Bug #19786: Data::define() does not work as documented https://bugs.ruby-lang.org/issues/19786#change-103994 * Author: thyresias (Thierry Lambert) * Status: Open * Priority: Normal * ruby -v: ruby 3.2.2 (2023-03-30 revision e51014f9c0) [x64-mingw-ucrt] * Backport: 3.0: UNKNOWN, 3.1: UNKNOWN, 3.2: UNKNOWN ---------------------------------------- Not sure if this is a bug or a feature. RDoc documentation for Data::define:
define(name, *symbols) → class define(*symbols) → class
Defines a new Data class. If the first argument is a string, the class is stored in Data::<name> constant.
```ruby M1 = Data.define('Measure', :amount, :unit) p M1 #=> M1 p M1.members #=> [:Measure, :amount, :unit] S1 = Struct.new('Measure', :amount, :unit) p S1 #=> Struct::Measure p S1.members #=> [:amount, :unit] ``` Unlike `Struct.new`, `Data.define` does not accept a name as first argument: it converts it to a symbol, and therefore a member. There is no trace of `Data::Measure` in the example above, while we do have `Struct::Measure`. -- https://bugs.ruby-lang.org/

Issue #19786 has been updated by thyresias (Thierry Lambert). zverok (Victor Shepelev) wrote in #note-1:
It's a documentation bug :( The first implementations of `Data` had this feature, but then Matz said it is not necessary (it is considered a legacy in Struct anyway), and I removed the feature but probably forgot to adjust the comments.
Already fixed in master: https://docs.ruby-lang.org/en/master/Data.html#method-c-define
Thank you Victor for the update. The behavior of Struct.new with a name is indeed a bit weird, so I was expecting this to be a feature rather than a bug, but I filed it since it was written in the ~~bible~~ documentation. ^_^ ---------------------------------------- Bug #19786: Data::define() does not work as documented https://bugs.ruby-lang.org/issues/19786#change-103995 * Author: thyresias (Thierry Lambert) * Status: Open * Priority: Normal * ruby -v: ruby 3.2.2 (2023-03-30 revision e51014f9c0) [x64-mingw-ucrt] * Backport: 3.0: UNKNOWN, 3.1: UNKNOWN, 3.2: UNKNOWN ---------------------------------------- Not sure if this is a bug or a feature. RDoc documentation for Data::define:
define(name, *symbols) → class define(*symbols) → class
Defines a new Data class. If the first argument is a string, the class is stored in Data::<name> constant.
```ruby M1 = Data.define('Measure', :amount, :unit) p M1 #=> M1 p M1.members #=> [:Measure, :amount, :unit] S1 = Struct.new('Measure', :amount, :unit) p S1 #=> Struct::Measure p S1.members #=> [:amount, :unit] ``` Unlike `Struct.new`, `Data.define` does not accept a name as first argument: it converts it to a symbol, and therefore a member. There is no trace of `Data::Measure` in the example above, while we do have `Struct::Measure`. -- https://bugs.ruby-lang.org/

Issue #19786 has been updated by nobu (Nobuyoshi Nakada). Status changed from Open to Closed Backport changed from 3.0: UNKNOWN, 3.1: UNKNOWN, 3.2: UNKNOWN to 3.0: DONTNEED, 3.1: DONTNEED, 3.2: REQUIRED It was fixed at commit:cada537040743cbe49aac6740816d648ca0d3fb6. To be backported. ---------------------------------------- Bug #19786: Data::define() does not work as documented https://bugs.ruby-lang.org/issues/19786#change-103997 * Author: thyresias (Thierry Lambert) * Status: Closed * Priority: Normal * ruby -v: ruby 3.2.2 (2023-03-30 revision e51014f9c0) [x64-mingw-ucrt] * Backport: 3.0: DONTNEED, 3.1: DONTNEED, 3.2: REQUIRED ---------------------------------------- Not sure if this is a bug or a feature. RDoc documentation for Data::define:
define(name, *symbols) → class define(*symbols) → class
Defines a new Data class. If the first argument is a string, the class is stored in Data::<name> constant.
```ruby M1 = Data.define('Measure', :amount, :unit) p M1 #=> M1 p M1.members #=> [:Measure, :amount, :unit] S1 = Struct.new('Measure', :amount, :unit) p S1 #=> Struct::Measure p S1.members #=> [:amount, :unit] ``` Unlike `Struct.new`, `Data.define` does not accept a name as first argument: it converts it to a symbol, and therefore a member. There is no trace of `Data::Measure` in the example above, while we do have `Struct::Measure`. -- https://bugs.ruby-lang.org/

Issue #19786 has been updated by nagachika (Tomoyuki Chikanaga). Backport changed from 3.0: DONTNEED, 3.1: DONTNEED, 3.2: REQUIRED to 3.0: DONTNEED, 3.1: DONTNEED, 3.2: DONE ruby_3_2 19a3466a1460924058ca16a259601bb753293d43 merged revision(s) cada537040743cbe49aac6740816d648ca0d3fb. ---------------------------------------- Bug #19786: Data::define() does not work as documented https://bugs.ruby-lang.org/issues/19786#change-104005 * Author: thyresias (Thierry Lambert) * Status: Closed * Priority: Normal * ruby -v: ruby 3.2.2 (2023-03-30 revision e51014f9c0) [x64-mingw-ucrt] * Backport: 3.0: DONTNEED, 3.1: DONTNEED, 3.2: DONE ---------------------------------------- Not sure if this is a bug or a feature. RDoc documentation for Data::define:
define(name, *symbols) → class define(*symbols) → class
Defines a new Data class. If the first argument is a string, the class is stored in Data::<name> constant.
```ruby M1 = Data.define('Measure', :amount, :unit) p M1 #=> M1 p M1.members #=> [:Measure, :amount, :unit] S1 = Struct.new('Measure', :amount, :unit) p S1 #=> Struct::Measure p S1.members #=> [:amount, :unit] ``` Unlike `Struct.new`, `Data.define` does not accept a name as first argument: it converts it to a symbol, and therefore a member. There is no trace of `Data::Measure` in the example above, while we do have `Struct::Measure`. -- https://bugs.ruby-lang.org/
participants (4)
-
nagachika (Tomoyuki Chikanaga)
-
nobu (Nobuyoshi Nakada)
-
thyresias (Thierry Lambert)
-
zverok (Victor Shepelev)