-
Notifications
You must be signed in to change notification settings - Fork 216
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update Struct #1621
Update Struct #1621
Conversation
core/struct.rbs
Outdated
@@ -243,7 +246,208 @@ class Struct[Elem] < Object | |||
# Any.new(1, 2) | |||
# # => #<struct Any foo=1, bar=2> | |||
# | |||
def initialize: (attribute_name, *attribute_name, ?keyword_init: boolish) ?{ () -> void } -> void | |||
def self.new: [K < _StructClass[Elem]] (string? classname, *interned fields, ?keyword_init: boolish?) ?{ (K) -> void } -> K |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After thinking about the type definitions and typical Ruby programs using Struct
, having a generic parameter here seems unnecessary to me.
def self.new: (string? classname, *interned fields, ?keyword_init: boolish?) ?{ (singleton(Struct)) [self: singleton(Struct)] -> void } -> untyped
| (Symbol field1, *interned fields, ?keyword_init: boolish?) ?{ (singleton(Struct)) [self: singleton(Struct)] -> void } -> untyped
Probably, having singleton(Struct)
as generic type upper bound would improve, but it looks like using untyped
makes sense here. (And we no longer need _StructClass
with the type definition.)
It looks like the |
a289138
to
8dbc310
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
I will try pushing commits with docs generated by bin/generate_docs
and see what happens.
This PR updates
Struct
's definitions, as well as adds in theHash::_Key
interface (needed forStruct#deconstruct_keys
), which will be used when I work onHash
.There's one small caveat: There's no real way to annotate
<subclass of Struct>.new
. After talking it over with @soutaro, we've decided it's fine and users can just add their ownnew
s type definitions if needed. e.g.:would become