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

Add Enum#inspect #13004

Merged

Conversation

straight-shoota
Copy link
Member

Implements Enum#inspect with a syntax based on Enum.[] (#12900) as proposed in #12884.

Resolves #12884

@straight-shoota
Copy link
Member Author

A question is what should happen to File::Permissions#inspect. It inherits the implementation from Enum. But #to_s has a custom implementation, so that got called from Enum#inspect.

In a41e48e I'm adjusting the specs for File::Permissions#inspect to match Enum#inspect:

perm.to_s    # => "rwxrw-r-- (0o764)"
perm.inspect # => "File::Permissions[OtherRead, GroupWrite, GroupRead, OwnerExecute, OwnerWrite, OwnerRead]"

But we could also go the other way and implement File::Permissions#inspect as delegating to ``File::Permissions#to_s`.

The #to_s is more concise and still unambiguous. It's not as clearly delimited though (it's only clear when you know what format to expect) and doesn't produce a valid expression.
So I'd prefer it this way, but we could alternatively have #inspect and #to_s be the same.

Copy link
Member

@beta-ziliani beta-ziliani left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's OK to have the verbose output for File::Permissions#inspect. As a developer I might be curious as to what are the real names of a given permission's flags.

@beta-ziliani beta-ziliani added this to the 1.8.0 milestone Feb 1, 2023
@straight-shoota straight-shoota merged commit aabd773 into crystal-lang:master Feb 2, 2023
@straight-shoota straight-shoota deleted the feature/enum-inspect branch February 2, 2023 14:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Enum#inspect should be more specific
2 participants