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 EOLconstant (End-Of-Line) #11303

Merged
merged 4 commits into from
Nov 10, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/kernel.cr
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,13 @@ ARGV = Array.new(ARGC_UNSAFE - 1) { |i| String.new(ARGV_UNSAFE[1 + i]) }
# ```
ARGF = IO::ARGF.new(ARGV, STDIN)

# The newline constant
EOL = {% if flag?(:windows) %}
"\r\n"
{% else %}
"\n"
{% end %}
Comment on lines +93 to +97
Copy link
Contributor

Choose a reason for hiding this comment

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

Could be shortened into:

Suggested change
EOL = {% if flag?(:windows) %}
"\r\n"
{% else %}
"\n"
{% end %}
EOL = {{ flag?(:windows) ? "\r\n" : "\n" }}

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 find ternary statements overly confusing. They only help reduce line count at the cost of readability.

Copy link
Member

Choose a reason for hiding this comment

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

I suppose you could also write it as {{ if flag?(:windows) "\r\n" else "\n" end }} if that's more approachable?
Anyway, these are all equivalent expressions of the same thing and there's no clear preference for one or the other. So let's keep it as is.


# Repeatedly executes the block.
#
# ```
Expand Down