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

.to_s/.inspect on tuples are not reversable #10707

Open
ryanstout opened this issue May 12, 2021 · 3 comments
Open

.to_s/.inspect on tuples are not reversable #10707

ryanstout opened this issue May 12, 2021 · 3 comments
Labels
good first issue This is an issue suited for newcomers to become aquianted with working on the codebase. help wanted This issue is generally accepted and needs someone to pick it up kind:feature topic:stdlib:collection

Comments

@ryanstout
Copy link

I'm programmatically generating some crystal code from a set of hardcoded config files in order to embed the data in the program. (Without the need to ship the config files)

Using a tuple as a key for a hash requires a space after the hash's opening { (to prevent the grammar from thinking its a macro) However, when calling .to_s on a hash with a tuple key, the output does not have the space. I always like where .to_s or inspect in other languages creates code you can paste back in if needed.

Would it make since to add a space around the { and } of tuples when calling .to_s?

A quick example of the output:

a = { {1,2} => true }
puts a
# {{1, 2} => true}

Thanks!

@Blacksmoke16
Copy link
Member

I always like where .to_s or inspect in other languages creates code you can paste back in if needed.

Related: #9966

@straight-shoota
Copy link
Member

Yeah, I would expect that you could turn a hash with simple data structures into code like that. Avoiding macro interpolation makes sense.

I don't think we want every tuple or hash wrapped in white space, though. That's probably gonna trigger some OCD.

It should be easy to implement for the specific cases where this applies: a hash or tuple as first element in a hash or tuple. For symmetry, we could also consider last elements, but that's a bit more complex. Without an opening delimiter, the closing delimiter }} should be harmless.

@straight-shoota straight-shoota added good first issue This is an issue suited for newcomers to become aquianted with working on the codebase. kind:feature topic:stdlib:collection help wanted This issue is generally accepted and needs someone to pick it up and removed status:discussion labels Mar 8, 2022
@simon1tan1
Copy link

I disagree. I think this is doing exactly what it is supposed to do.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue This is an issue suited for newcomers to become aquianted with working on the codebase. help wanted This issue is generally accepted and needs someone to pick it up kind:feature topic:stdlib:collection
Projects
None yet
Development

No branches or pull requests

4 participants