Ruby here document example

1 Oct 2009

A nice ruby example (for my reference) of using here documents to load data/logic. From Pragmattic Programmers’ Best of Ruby Quiz:

DIGITS = <<END_DIGITS.split("n").map { |row| row.split(" # ") }.transpose
 -  #     #  -  #  -  #     #  -  #  -  #  -  #  -  #  -
| | #   | #   | #   | # | | # |   # |   #   | # | | # | |
    #     #  -  #  -  #  -  #  -  #  -  #     #  -  #  -
| | #   | # |   #   | #   | #   | # | | #   | # | | #   |
 -  #     #  -  #  -  #     #  -  #  -  #     #  -  #  -
END_DIGITS
comments powered by Disqus

  « Previous: Next: »