-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Anonymous Struct literal ${a:1, b:2}
#3259
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
Conversation
It's a fun idea. I can see many usage. |
Try to introduce anonymous Struct literal. ${a:1, b:2} is equal to Struct.new(kw.keys).new(kw.values) where kw is {a:1, b:2}.
If members of literal struct are same and same order, they share same class. Also fix ISeq#to_binary, .load_from_binary.
I always wanted something short like this, but do you think we could have something more explicit and verbose like |
{ | ||
/*%%%*/ | ||
$$ = new_struct(p, $3, &@$); | ||
$$->nd_brace = TRUE; |
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.
This seems unnecessary, because it is not a NODE_HASH
.
Please DO NOT discuss spec here. Please write a comment on redmine ticket. |
just delegate |
Try to introduce anonymous Struct literal.
https://bugs.ruby-lang.org/issues/16986
${a:1, b:2}
is almost equal toStruct.new(kw.keys).new(kw.values)
wherekw
is{a:1, b:2}
.Anonymous class is prepared at compile time.