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

Document ASTNode#symbolize #5081

Merged
merged 1 commit into from Oct 6, 2017

Conversation

Sija
Copy link
Contributor

@Sija Sija commented Oct 5, 2017

SSIA, couldn't find it in the docs so went ahead and fixed it up :)

# {{ "foo".symbolize }}
# end
#
# puts test # prints "foo" (including the double quotes)
Copy link
Member

Choose a reason for hiding this comment

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

Maybe is cleaner to show {{ "foo".symbolize }} == :"\"foo\"" # => true.

I am not 100% why the double quotes are included in the symbol value though.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was wondering the same :) @asterite, would you please tell us why❓

Copy link
Member

Choose a reason for hiding this comment

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

The textual representation of "foo" is "foo", and so a symbol with "foo" is :"\"foo\". If you want :foo you need to do "foo".id.symbolize.

Copy link
Member

Choose a reason for hiding this comment

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

Also "foo".stringify makes a string literal out of that, so it becomes "\"foo\"". The two methods are similar.

@Sija Sija force-pushed the macros-astnode-stringify-docs branch from 0d7efe8 to 8063ae8 Compare October 5, 2017 23:45
@Sija
Copy link
Contributor Author

Sija commented Oct 6, 2017

@bcardiff updated code example to match eye expectations (though usage of .id might seem cryptic)

@RX14 RX14 added the kind:docs label Oct 6, 2017
@RX14 RX14 added this to the Next milestone Oct 6, 2017
@RX14 RX14 merged commit f0d609c into crystal-lang:master Oct 6, 2017
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.

None yet

4 participants