From: "matz (Yukihiro Matsumoto) via ruby-core" Date: 2023-03-09T05:08:15+00:00 Subject: [ruby-core:112757] [Ruby master Bug#19416] Inconsistent behaviour for Struct.new without any member_names Issue #19416 has been updated by matz (Yukihiro Matsumoto). After consideration, I think we should allow empty `Struct` even without the name for consistency. Matz. ---------------------------------------- Bug #19416: Inconsistent behaviour for Struct.new without any member_names https://bugs.ruby-lang.org/issues/19416#change-102250 * Author: herwin (Herwin W) * Status: Open * Priority: Normal * ruby -v: ruby 3.1.2p20 (2022-04-12 revision 4491bb740a) [x86_64-linux-gnu] * Backport: 2.7: UNKNOWN, 3.0: UNKNOWN, 3.1: UNKNOWN, 3.2: UNKNOWN ---------------------------------------- When I simply declare a Struct without any arguments, I get an error: ``` irb(main):001:0> Struct.new (irb):1:in `new': wrong number of arguments (given 0, expected 1+) (ArgumentError) from (irb):1:in `
' ``` But Struct has an option to pass a class name as the first argument, which will create the struct as a constant in the Struct namespace. If this argument is given, there is no ArgumentError ``` irb(main):002:0> Struct.new('Foo') => Struct::Foo ``` This results in a rather pointless class ``` irb(main):003:0> Struct::Foo.new(1) (irb):3:in `initialize': struct size differs (ArgumentError) from (irb):3:in `new' irb(main):004:0> Struct::Foo.new => # ``` This behaviour is not documented in the Struct class, but I would guess this is not how it is intended to be. -- 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/postorius/lists/ruby-core.ml.ruby-lang.org/