« first day (1066 days earlier)      last day (1384 days later) » 

2:00 AM
Anyway, the main difference in terms of functionality (if it can be called that) is that here documents in Bourne-style shells can either retain or drop leading tab characters, depending on whether one writes a - before the initial appearance of the delimiter or not, i.e., depending on whether one writes something like <<EOF or <<-EOF (where EOF is replaced with whatever delimiter one wishes to use).
In contrast, Crystal here documents always syntactically introduce their delimiter after a - but with a different meaning than either having it or not in a Bourne-style shell. In Bourne-style shells, the closing delimiter must never have leading whitespace. In Crystal, the closing delimiter may have leading whitespace, and that much leading whitespace is removed from each line in the here document.
 
2:15 AM
With this Crystal code:
count0 = <<-STOP.count &.whitespace?
  one two three
  four five six
  seven eight nine
STOP
puts "There are #{count0} whitespace characters with an unindented delimiter."

count1 = <<-STOP.count &.whitespace?
  one two three
  four five six
  seven eight nine
 STOP
puts "There are #{count1} whitespace characters with a slighly indented delimiter."

count2 = <<-STOP.count &.whitespace?
  one two three
  four five six
  seven eight nine
  STOP
puts "There are #{count2} whitespace characters with a more indented delimiter."
I get:
There are 14 whitespace characters with an unindented delimiter.
There are 11 whitespace characters with a slighly indented delimiter.
There are 8 whitespace characters with a more indented delimiter.
If I then append this to the code:
count3 = <<-STOP.count &.whitespace?
  one two three
  four five six
  seven eight nine
    STOP
puts "There are #{count3} whitespace characters with an overly indented delimiter."
Then the Crystal compiler refuses to compile it at all, saying:
In leading.cr:23:1

 23 | one two three
    ^
Error: heredoc line must have an indent greater than or equal to 4
 
3:14 AM
@EliahKagan TIL strings (and not just File objects) have .lines which is nicer than .split('\n'), so that can be written:
<<-'EOF'.lines.zip(<<-'EOF'.lines) { |a, b| puts "#{a} #{b}" }
'Twas brillig, and
Did gyre and
All mimsy were
And the
EOF
the slithy toves
gimble in the wabe
the borogroves,
mome raths outgrabe.
EOF
(Ruby also has .lines, including for strings, but in Ruby it keeps the newline characters at the end. In Crystal it removes them. In Ruby one can use .lines.map(&:chomp). In Crystal one could write .lines.map(&.chomp) but there's no need, since .lines in Crystal are already chomped.)
 

« first day (1066 days earlier)      last day (1384 days later) »