[#111472] [Ruby master Bug#19274] Error installing ruby 3.2.0 on RH 8 — "aalllop (Alberto Allegue) via ruby-core" <ruby-core@...>
Issue #19274 has been reported by aalllop (Alberto Allegue).
5 messages
2022/12/28
[#111508] Data support for versions before 3.2.0 — Eustáquio Rangel via ruby-core <ruby-core@...>
I was wondering that every piece of code (gems, etc) that use the new Data =
3 messages
2022/12/29
[ruby-core:111543] [Ruby master Bug#19278] Constructing subclasses of Data with positional arguments
From:
"tenderlovemaking (Aaron Patterson) via ruby-core" <ruby-core@...>
Date:
2022-12-30 18:48:35 UTC
List:
ruby-core #111543
Issue #19278 has been updated by tenderlovemaking (Aaron Patterson).
zverok (Victor Shepelev) wrote in #note-8:
> BTW, note that before 3.2, for structs it was either `keyword_init: false`, or `keyword_init: true`, not both.
>
> That's why you were able to easily redefine `initialize`: you _knew_ it receives either keywords or positionals, not "both and need to choose". After 3.2, it is different, and I think that people would stumble on that many times (the design decision was made differently, too, unlike Data):
> ```ruby
> S = Struct.new(:x) do
> def initialize(*a, **kwa)
> puts "a=#{a}, kwa=#{kwa}"
> end
> end
> S.new(1)
> # a=[1], kwa={}
> S.new(x: 1)
> # a=[], kwa={:x=>1}
> ```
I don't really understand this example. The `initialize` works the same way whether you use a Struct or not:
```ruby
S = Struct.new(:x) do
def initialize(*a, **kwa)
puts "a=#{a}, kwa=#{kwa}"
end
end
S.new(1)
# a=[1], kwa={}
S.new(x: 1)
# a=[], kwa={:x=>1}
class K
def initialize(*a, **kwa)
puts "a=#{a}, kwa=#{kwa}"
end
end
K.new(1)
# a=[1], kwa={}
K.new(x: 1)
# a=[], kwa={:x=>1}
```
> I think it will cause a fair share of confusion in completely different ways than the design choice for `Data` did :)
`Data` is confusing for me _because_ it doesn't share the same behavior as a regular class (where Struct does).
Eregon (Benoit Daloze) wrote in #note-9:
> To clarify:
>
> > Also inheriting from a Data class seems kind of an anti/rare pattern.
>
> I meant one should use `Struct.new(...) { ... }` / `Data.define(...) { ... }` and not `class < Struct.new(...)` / `class < Data.define(...)` which is wasteful because it creates an extra class and makes the hierarchy needlessly one level deeper (and also causes an unnamed supercass).
Sure, but making a class that eventually inherits from a class defined via `Struct.new` is something I normally do. I wanted to do the same thing with `Data`, but found I could not because it defines `new` differently.
----------------------------------------
Bug #19278: Constructing subclasses of Data with positional arguments
https://bugs.ruby-lang.org/issues/19278#change-100907
* Author: tenderlovemaking (Aaron Patterson)
* Status: Feedback
* Priority: Normal
* ruby -v: ruby 3.2.0 (2022-12-25 revision a528908271) [arm64-darwin22]
* Backport: 2.7: UNKNOWN, 3.0: UNKNOWN, 3.1: UNKNOWN, 3.2: UNKNOWN
----------------------------------------
I'd expect both of the following subclasses to work, but the subclass that uses positional parameters raises an exception:
```ruby
Foo = Data.define
class Bar < Foo
def initialize foo:
p foo
end
end
class Baz < Foo
def initialize foo
p foo
end
end
Bar.new foo: 1 # Prints 1
Baz.new 1 # Raises ArgumentError
```
I'd expect the subclass that uses positional arguments to work.
--
https://bugs.ruby-lang.org/
______________________________________________
ruby-core mailing list -- [email protected]
To unsubscribe send an email to [email protected]
ruby-core info -- https://ml.ruby-lang.org/mailman3/postorius/lists/ruby-core.ml.ruby-lang.org/