Project

General

Profile

Actions

Bug #19786

closed

Data::define() does not work as documented

Added by thyresias (Thierry Lambert) 10 months ago. Updated 10 months ago.

Status:
Closed
Assignee:
-
Target version:
-
ruby -v:
ruby 3.2.2 (2023-03-30 revision e51014f9c0) [x64-mingw-ucrt]
[ruby-core:114295]

Description

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:: constant.

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.

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0