This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| defmodule Bottles do | |
| def song do | |
| verses(99, 0) | |
| end | |
| def verses(first, last) do | |
| first..last | |
| |> Enum.map_join("\n", &verse(&1)) | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Bottles | |
| def song | |
| verses(99, 0) | |
| end | |
| def verses(first, last) | |
| first.downto(last).map { |n| verse(n) }.join("\n") | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def assert( bool, msg ) | |
| puts (bool ? "Pass " : "Fail ") + msg | |
| end | |
| class Hash | |
| def destruct( &block ) | |
| vals = block.parameters.map { |p| self[p[1]] } | |
| block.call(*vals) | |
| end | |
| end |