Thanks to visit codestin.com
Credit goes to github.com

Skip to content

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

Closed
wants to merge 8 commits into from
Closed

Conversation

ko1
Copy link
Contributor

@ko1 ko1 commented Jun 25, 2020

Try to introduce anonymous Struct literal.
https://bugs.ruby-lang.org/issues/16986

${a:1, b:2} is almost equal to Struct.new(kw.keys).new(kw.values) where kw is {a:1, b:2}.
Anonymous class is prepared at compile time.

@ko1 ko1 marked this pull request as draft June 25, 2020 22:06
@ioquatix
Copy link
Member

It's a fun idea.

I can see many usage.

ko1 added 7 commits June 26, 2020 15:23
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.
@ko1 ko1 force-pushed the struct_literal branch from 49dcd6f to 1193ce6 Compare June 26, 2020 06:24
@ko1 ko1 marked this pull request as ready for review June 26, 2020 06:58
@ys
Copy link

ys commented Jun 26, 2020

I always wanted something short like this, but do you think we could have something more explicit and verbose like struct(a:1, b:2). Single symbols always end up with people googling around weirdly to find which one it is!

{
/*%%%*/
$$ = new_struct(p, $3, &@$);
$$->nd_brace = TRUE;
Copy link
Member

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.

@ko1
Copy link
Contributor Author

ko1 commented Jun 27, 2020

Please DO NOT discuss spec here. Please write a comment on redmine ticket.

@pynixwang
Copy link

just delegate method_missing to [], then you can use . syntax

@ko1 ko1 closed this Dec 14, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants