Skip to content
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

Anonymous Struct literal ${a:1, b:2} #3259

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open

Anonymous Struct literal ${a:1, b:2} #3259

wants to merge 8 commits into from

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 Jun 25, 2020
compile.c Outdated Show resolved Hide resolved
@ioquatix
Copy link
Member

@ioquatix ioquatix commented Jun 26, 2020

It's a fun idea.

I can see many usage.

ko1 added 7 commits Jun 25, 2020
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 ko1:struct_literal branch from 49dcd6f to 1193ce6 Jun 26, 2020
@ko1 ko1 marked this pull request as ready for review Jun 26, 2020
@ys
Copy link

@ys 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;

This comment has been minimized.

@nobu

nobu Jun 26, 2020
Member

This seems unnecessary, because it is not a NODE_HASH.

@ko1
Copy link
Contributor Author

@ko1 ko1 commented Jun 27, 2020

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

@pynixwang
Copy link

@pynixwang pynixwang commented Jul 6, 2020

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
5 participants