Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Succession

 Succession

Refactoring sometimes devolves into an appalling mess. You're chasing a broken test suite, and every change just makes it worse. At other times it's a slow, controlled process culminating in dreadful design.

This talk presents an end-to-end refactoring that demonstrates simple strategies to avoid such misadventures.

Katrina Owen

May 06, 2016
Tweet

More Decks by Katrina Owen

Other Decks in Programming

Transcript

  1. I know an old lady who swallowed a . spider

    She swallowed the spider to catch the fly.
  2. I know an old lady who swallowed a . bird

    She swallowed the bird to catch the spider. She swallowed the spider to catch the fly.
  3. I know an old lady who swallowed a . cat

    She swallowed the cat to catch the bird. She swallowed the bird to catch the spider. She swallowed the spider to catch the fly.
  4. I know an old lady who swallowed a . dog

    She swallowed the dog to catch the cat. She swallowed the cat to catch the bird. She swallowed the bird to catch the spider. She swallowed the spider to catch the fly.
  5. I know an old lady who swallowed a . goat

    She swallowed the goat to catch the dog. She swallowed the dog to catch the cat. She swallowed the cat to catch the bird. She swallowed the bird to catch the spider. She swallowed the spider to catch the fly.
  6. I know an old lady who swallowed a . cow

    She swallowed the cow to catch the goat. She swallowed the goat to catch the dog. She swallowed the dog to catch the cat. She swallowed the cat to catch the bird. She swallowed the bird to catch the spider. She swallowed the spider to catch the fly.
  7. / %@. @# @@@@( (@. ,@@@@@@@@, ,@% #@@@@@@@@@@@ .@& (@@@@@@@@@@@@@%

    @@( *@@@@@@@@@@@@@@@ (@@/ ,@@@@@@@@@@@@@@@@@, @/ @@@, %@@@@@@@@@@@@@@@@@@/ &@( &@@@ @@@@@@@@@@@@@@@@@@@@# &@/ @@@@. @@@@@@@@@@@@@@@@@@@@@/ &@# ,@@@( /@@@@@@@@@@@@@@@@@@@@@, %@& (@@, @@@. #@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ &@@. @@/ /@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@&/ &@@% /@@, %@@@@@@@@@@@@@@@@@@@@@@@@@/ %@@@. %@@* .@@@@@@@@@@@@@@@@@@@@@@@@@@@ %@@@/ @@@, &@@@@@@@@@@@@@@@@@@@@@@@@@@@& ./(%##////#. ,@@@@@@,,,.,.,.... ,@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@& *&@@@@@@@@@@@@@@@@@#. @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@# .&@@@@@& @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@/ /@@@@@&@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@# /@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@# ,,. #@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@* %@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@&(*. (%%%&@&&@@@@ (@@@* /@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@* &@@@@@, . (@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@& ,@@@@* *@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@( *@@@& @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@/ #, &@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@. ,%@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@&, /@@#&@@@@@@@& ,#@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@% *@@@@@@@@@@@@@ @@@@ ,@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@( .(@@@@@@@@% .@@@& (@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ ,@@@% &@@@@/,(#@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@. (@@@ #@@@@# .*,(@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@/ (@@@ @@@@ .,(#%&&@@@@@@@@@@@@@@@@@, *@@@% .@@@, .,*(##(*, ,@@@@@@/ @@@(. .@@@@( /@@@@@@&%((/, *@@@@ .*#&@@@@@@/ .@@@& ,@@&, *@@( (@@@. (@& *&% /@# /@. *@. %*
  8. What a hog, to swallow a dog! She swallowed the

    dog to catch the She swallowed the cat to catch the She swallowed the bird to catch th She swallowed the spider to catch I don't know why she swallowed the I know an old lady who swallowed a Just opened her throat and swallow
  9. <<-SONG I know an old lady who swallowed a fly.

    # ... She's dead, of course! SONG
  10. def lyrics <<-SONG I know an old lady who swallowed

    a fly. # ... She's dead, of course! SONG end
  11. class Song def lyrics <<-SONG I know an old lady

    who swallowed a fly. # ... She's dead, of course! SONG end end
  12. class SongTest < Minitest::Test def test_lyrics <<-SONG I know an

    old lady who swallowed a fly. # ... She's dead, of course! SONG end end
  13. class SongTest < Minitest::Test def test_lyrics expected = <<-SONG I

    know an old lady who swallowed a fly. # ... She's dead, of course! SONG assert_equal expected, Song.new.song end end
  14. It wriggled and jiggled and tickled inside her. She swallowed

    the spider to catch the fly. I don't know why she swallowed the fly. Perhaps she'll I know an old lady who swallowed a bird. How absurd to swallow a bird! She swallowed the bird to catch the spider that wriggle She swallowed the spider to catch the fly. I don't know why she swallowed the fly. Perhaps she'll I know an old lady who swallowed a cat. Imagine that, to swallow a cat! She swallowed the cat to catch the bird. She swallowed the bird to catch the spider that wriggle She swallowed the spider to catch the fly. I don't know why she swallowed the fly. Perhaps she'll
  15. # ... I know an old lady who swallowed a

    fly. # ... I know an old lady who swallowed a spider. # ... I know an old lady who swallowed a bird. # ... I know an old lady who swallowed a cat. # ... I know an old lady who swallowed a dog. # ... I know an old lady who swallowed a goat. # ... I know an old lady who swallowed a cow. # ... I know an old lady who swallowed a horse. # ...
  16. # ... She swallowed the dog to catch the cat.

    She swallowed the cat to catch the bird. She swallowed the bird to catch the spider that wriggled and She swallowed the spider to catch the fly. # ... She swallowed the goat to catch the dog. She swallowed the dog to catch the cat. She swallowed the cat to catch the bird. She swallowed the bird to catch the spider that wriggled and She swallowed the spider to catch the fly. # ... She swallowed the cow to catch the goat. She swallowed the goat to catch the dog. She swallowed the dog to catch the cat. She swallowed the cat to catch the bird. She swallowed the bird to catch the spider that wriggled and
  17. I know an old lady who swallowed a dog. What

    a hog, to swallow a dog! She swallowed the dog to catch the cat. She swallowed the cat to catch the bird. She swallowed the bird to catch the spider that wriggled and She swallowed the spider to catch the fly. I don't know why she swallowed the fly. Perhaps she'll die. I know an old lady who swallowed a goat. Just opened her throat and swallowed a goat! She swallowed the goat to catch the dog. She swallowed the dog to catch the cat. She swallowed the cat to catch the bird. She swallowed the bird to catch the spider that wriggled and She swallowed the spider to catch the fly. I don't know why she swallowed the fly. Perhaps she'll die.
  18. <<-SONG I know an old lady who swallowed a fly.

    I don't know why she swallowed the fly. Perhaps she'll die. I know an old lady who swallowed a spider. It wriggled and jiggled and tickled inside her. She swallowed the spider to catch the fly. I don't know why she swallowed the fly. Perhaps she'll die. I know an old lady who swallowed a bird. How absurd to swallow a bird! She swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her. She swallowed the spider to catch the fly. I don't know why she swallowed the fly. Perhaps she'll die. I know an old lady who swallowed a cat. Imagine that, to swallow a cat! She swallowed the cat to catch the bird. She swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her. She swallowed the spider to catch the fly. I don't know why she swallowed the fly. Perhaps she'll die. I know an old lady who swallowed a dog. What a hog, to swallow a dog! She swallowed the dog to catch the cat. She swallowed the cat to catch the bird. She swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her. She swallowed the spider to catch the fly. I don't know why she swallowed the fly. Perhaps she'll die. I know an old lady who swallowed a goat. Just opened her throat and swallowed a goat! She swallowed the goat to catch the dog. She swallowed the dog to catch the cat. She swallowed the cat to catch the bird. She swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her. She swallowed the spider to catch the fly. I don't know why she swallowed the fly. Perhaps she'll die. I know an old lady who swallowed a cow. I don't know how she swallowed a cow! She swallowed the cow to catch the goat. She swallowed the goat to catch the dog. She swallowed the dog to catch the cat. She swallowed the cat to catch the bird. She swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her. She swallowed the spider to catch the fly. I don't know why she swallowed the fly. Perhaps she'll die. I know an old lady who swallowed a horse. She's dead, of course! SONG
  19. case i when 1 "I know an old lady who

    swallowed a fly.\n" + "I don't know why she swallowed the fly. Perhaps...\n" when 2 "I know an old lady who swallowed a spider.\n" + "It wriggled and jiggled and tickled inside her.\n" + "She swallowed the spider to catch the fly.\n" + "I don't know why she swallowed the fly. Perhaps...\n" when 3 "I know an old lady who swallowed a bird.\n" + "How absurd to swallow a bird!\n" + "She swallowed the bird to catch the spider that..." + "She swallowed the spider to catch the fly.\n" + "I don't know why she swallowed the fly. Perhaps...\n" when 4
  20. def lyrics (1..8).map {|i| case i when 1 # ...

    when n # ... end }.join("\n") end
  21. def song (1..8).map {|i| case i when 1 # ...

    when n # ... end }.join("\n") end
  22. case i when 1 "I know an old lady who

    swallowed a fly.\n" + "I don't know why she swallowed the fly. Perhaps she'l when 2 "I know an old lady who swallowed a spider.\n" + "It wriggled and jiggled and tickled inside her.\n" + "She swallowed the spider to catch the fly.\n" + "I don't know why she swallowed the fly. Perhaps she'l when 3 "I know an old lady who swallowed a bird.\n" + "How absurd to swallow a bird!\n" + "She swallowed the bird to catch the spider that wrigg "She swallowed the spider to catch the fly.\n" + "I don't know why she swallowed the fly. Perhaps she'l
  23. case i when 1 "I know an old lady who

    swallowed a fly.\n" + "I don't know why she swallowed the fly. Perhaps she'l when 2 "I know an old lady who swallowed a spider.\n" + "It wriggled and jiggled and tickled inside her.\n" + "She swallowed the spider to catch the fly.\n" + "I don't know why she swallowed the fly. Perhaps she'l when 3 "I know an old lady who swallowed a bird.\n" + "How absurd to swallow a bird!\n" + "She swallowed the bird to catch the spider that wrigg "She swallowed the spider to catch the fly.\n" + "I don't know why she swallowed the fly. Perhaps she'l
  24. case i when 1 "I know an old lady who

    swallowed a fly.\n" + "I don't know why she swallowed the fly. Perhaps she'l when 2 "I know an old lady who swallowed a spider.\n" + "It wriggled and jiggled and tickled inside her.\n" + "She swallowed the spider to catch the fly.\n" + "I don't know why she swallowed the fly. Perhaps she'l when 3 "I know an old lady who swallowed a bird.\n" + "How absurd to swallow a bird!\n" + "She swallowed the bird to catch the spider that wrigg "She swallowed the spider to catch the fly.\n" + "I don't know why she swallowed the fly. Perhaps she'l
  25. case i when 1 "I know an old lady who

    swallowed a fly.\n" + "I don't know why she swallowed the fly. Perhaps she'l when 2 "I know an old lady who swallowed a spider.\n" + "It wriggled and jiggled and tickled inside her.\n" + "She swallowed the spider to catch the fly.\n" + "I don't know why she swallowed the fly. Perhaps she'l when 3 "I know an old lady who swallowed a bird.\n" + "How absurd to swallow a bird!\n" + "She swallowed the bird to catch the spider that wrigg "She swallowed the spider to catch the fly.\n" + "I don't know why she swallowed the fly. Perhaps she'l
  26. case i when 1 "I know an old lady who

    swallowed a fly.\n" when 2 "I know an old lady who swallowed a spider.\n" when 3 "I know an old lady who swallowed a bird.\n" when 4 "I know an old lady who swallowed a cat.\n" when 5 "I know an old lady who swallowed a dog.\n" when 6 "I know an old lady who swallowed a goat.\n" when 7 "I know an old lady who swallowed a cow.\n" when 8 "I know an old lady who swallowed a horse.\n" end
  27. case i when 1 "I know an old lady who

    swallowed a %s.\n" % "fly" when 2 "I know an old lady who swallowed a %s.\n" % "spider" when 3 "I know an old lady who swallowed a %s.\n" % "bird" when 4 "I know an old lady who swallowed a %s.\n" % "cat" when 5 "I know an old lady who swallowed a %s.\n" % "dog" when 6 "I know an old lady who swallowed a %s.\n" % "goat" when 7 "I know an old lady who swallowed a %s.\n" % "cow" when 8 "I know an old lady who swallowed a %s.\n" % "horse" end
  28. case i when 1 "I know an old lady who

    swallowed a %s.\n" % "fly" when 2 "I know an old lady who swallowed a %s.\n" % "spider" when 3 "I know an old lady who swallowed a %s.\n" % "bird" when 4 "I know an old lady who swallowed a %s.\n" % "cat" when 5 "I know an old lady who swallowed a %s.\n" % "dog" when 6 "I know an old lady who swallowed a %s.\n" % "goat" when 7 "I know an old lady who swallowed a %s.\n" % "cow" when 8 "I know an old lady who swallowed a %s.\n" % "horse" end
  29. "She swallowed the bird to catch the spider that wrig

    "She swallowed the spider to catch the fly.\n" + when 6 "She swallowed the goat to catch the dog.\n" + "She swallowed the dog to catch the cat.\n" + "She swallowed the cat to catch the bird.\n" + "She swallowed the bird to catch the spider that wrig "She swallowed the spider to catch the fly.\n" + when 7 "She swallowed the cow to catch the goat.\n" + "She swallowed the goat to catch the dog.\n" + "She swallowed the dog to catch the cat.\n" + "She swallowed the cat to catch the bird.\n" + "She swallowed the bird to catch the spider that wrig "She swallowed the spider to catch the fly.\n" + when 8
  30. "She swallowed the %s to catch the %s.\n" % ["bird",

    "She swallowed the %s to catch the %s.\n" % ["spider when 6 "She swallowed the %s to catch the %s.\n" % ["goat", "She swallowed the %s to catch the %s.\n" % ["dog", "She swallowed the %s to catch the %s.\n" % ["cat", "She swallowed the %s to catch the %s.\n" % ["bird", "She swallowed the %s to catch the %s.\n" % ["spider when 7 "She swallowed the %s to catch the %s.\n" % ["goat", "She swallowed the %s to catch the %s.\n" % ["dog", "She swallowed the %s to catch the %s.\n" % ["cat", "She swallowed the %s to catch the %s.\n" % ["bird", "She swallowed the %s to catch the %s.\n" % ["spider "She swallowed the %s to catch the %s.\n" % ["spider when 8
  31. "I know an old lady who swallowed a %s.\n" %

    "%s\n" % "She swallowed the %s to catch the %s.\n" % "She swallowed the %s to catch the %s.\n" % "She swallowed the %s to catch the %s.\n" % "She swallowed the %s to catch the %s.\n" % "She swallowed the %s to catch the %s.\n" % "She swallowed the %s to catch the %s.\n" % "%s\n" %
  32. % "cow" + % "I don't know how she swallowed

    a cow!" + % ["cow", "goat"] + % ["goat", "dog"] + % ["dog", "cat"] + % ["cat", "bird"] + % ["bird", "spider that wriggled and..."] + % ["spider", "fly"] + % "I don't know why she swallowed the fly...
  33. <<-SONG I know an old lady who swallowed a fly.

    I don't know why she swallowed the fly. Perhaps she'll die. I know an old lady who swallowed a spider. It wriggled and jiggled and tickled inside her. She swallowed the spider to catch the fly. I don't know why she swallowed the fly. Perhaps she'll die. I know an old lady who swallowed a bird. How absurd to swallow a bird! She swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her. She swallowed the spider to catch the fly. I don't know why she swallowed the fly. Perhaps she'll die. I know an old lady who swallowed a cat. Imagine that, to swallow a cat! She swallowed the cat to catch the bird. She swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her. She swallowed the spider to catch the fly. I don't know why she swallowed the fly. Perhaps she'll die. I know an old lady who swallowed a dog. What a hog, to swallow a dog! She swallowed the dog to catch the cat. She swallowed the cat to catch the bird. She swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her. She swallowed the spider to catch the fly. I don't know why she swallowed the fly. Perhaps she'll die. I know an old lady who swallowed a goat. Just opened her throat and swallowed a goat! She swallowed the goat to catch the dog. She swallowed the dog to catch the cat. She swallowed the cat to catch the bird. She swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her. She swallowed the spider to catch the fly. I don't know why she swallowed the fly. Perhaps she'll die. I know an old lady who swallowed a cow. I don't know how she swallowed a cow! She swallowed the cow to catch the goat. She swallowed the goat to catch the dog. She swallowed the dog to catch the cat. She swallowed the cat to catch the bird. She swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her. She swallowed the spider to catch the fly. I don't know why she swallowed the fly. Perhaps she'll die. I know an old lady who swallowed a horse. She's dead, of course! SONG
  34. case i when 1 "I know an old lady who

    swallowed a fly.\n" + "I don't know why she swallowed the fly. Perhaps she'll die.\n" when 2 "I know an old lady who swallowed a spider.\n" + "It wriggled and jiggled and tickled inside her.\n" + "She swallowed the spider to catch the fly.\n" + "I don't know why she swallowed the fly. Perhaps she'll die.\n" when 3 "I know an old lady who swallowed a bird.\n" + "How absurd to swallow a bird!\n" + "She swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her.\n" + "She swallowed the spider to catch the fly.\n" + "I don't know why she swallowed the fly. Perhaps she'll die.\n" when 4 "I know an old lady who swallowed a cat.\n" + "Imagine that, to swallow a cat!\n" + "She swallowed the cat to catch the bird.\n" + "She swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her.\n" + "She swallowed the spider to catch the fly.\n" + "I don't know why she swallowed the fly. Perhaps she'll die.\n" when 5 "I know an old lady who swallowed a dog.\n" + "What a hog, to swallow a dog!\n" + "She swallowed the dog to catch the cat.\n" + "She swallowed the cat to catch the bird.\n" + "She swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her.\n" + "She swallowed the spider to catch the fly.\n" + "I don't know why she swallowed the fly. Perhaps she'll die.\n" when 6 "I know an old lady who swallowed a goat.\n" + "Just opened her throat and swallowed a goat!\n" + "She swallowed the goat to catch the dog.\n" + "She swallowed the dog to catch the cat.\n" + "She swallowed the cat to catch the bird.\n" + "She swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her.\n" + "She swallowed the spider to catch the fly.\n" + "I don't know why she swallowed the fly. Perhaps she'll die.\n" when 7 "I know an old lady who swallowed a cow.\n" + "I don't know how she swallowed a cow!\n" + "She swallowed the cow to catch the goat.\n" + "She swallowed the goat to catch the dog.\n" + "She swallowed the dog to catch the cat.\n" + "She swallowed the cat to catch the bird.\n" + "She swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her.\n" + "She swallowed the spider to catch the fly.\n" + "I don't know why she swallowed the fly. Perhaps she'll die.\n" when 8 "I know an old lady who swallowed a horse.\n" + "She's dead, of course!\n" end
  35. case i when 1 "I know an old lady who

    swallowed a %s.\n" % "fly" + "%s\n" % "I don't know why she swallowed the fly. Perhaps she'll die." when 2 "I know an old lady who swallowed a %s.\n" % "spider" + "%s\n" % "It wriggled and jiggled and tickled inside her." + "She swallowed the %s to catch the %s.\n" % ["spider", "fly"] + "%s\n" % "I don't know why she swallowed the fly. Perhaps she'll die." when 3 "I know an old lady who swallowed a %s.\n" % "bird" + "%s\n" % "How absurd to swallow a bird!" + "She swallowed the %s to catch the %s.\n" % ["bird", "spider that wriggled and jiggled and tickled inside her"] + "She swallowed the %s to catch the %s.\n" % ["spider", "fly"] + "%s\n" % "I don't know why she swallowed the fly. Perhaps she'll die." when 4 "I know an old lady who swallowed a %s.\n" % "cat"+ "%s\n" % "Imagine that, to swallow a cat!" + "She swallowed the %s to catch the %s.\n" % ["cat", "bird"] + "She swallowed the %s to catch the %s.\n" % ["bird", "spider that wriggled and jiggled and tickled inside her"] + "She swallowed the %s to catch the %s.\n" % ["spider", "fly"] + "%s\n" % "I don't know why she swallowed the fly. Perhaps she'll die." when 5 "I know an old lady who swallowed a %s.\n" % "dog" + "%s\n" % "What a hog, to swallow a dog!" + "She swallowed the %s to catch the %s.\n" % ["dog", "cat"] + "She swallowed the %s to catch the %s.\n" % ["cat", "bird"] + "She swallowed the %s to catch the %s.\n" % ["bird", "spider that wriggled and jiggled and tickled inside her"] + "She swallowed the %s to catch the %s.\n" % ["spider", "fly"] + "%s\n" % "I don't know why she swallowed the fly. Perhaps she'll die." when 6 "I know an old lady who swallowed a %s.\n" % "goat" + "%s\n" % "Just opened her throat and swallowed a goat!" + "She swallowed the %s to catch the %s.\n" % ["goat", "dog"] + "She swallowed the %s to catch the %s.\n" % ["dog", "cat"] + "She swallowed the %s to catch the %s.\n" % ["cat", "bird"] + "She swallowed the %s to catch the %s.\n" % ["bird", "spider that wriggled and jiggled and tickled inside her"] + "She swallowed the %s to catch the %s.\n" % ["spider", "fly"] + "%s\n" % "I don't know why she swallowed the fly. Perhaps she'll die." when 7 "I know an old lady who swallowed a %s.\n" % "cow" + "%s\n" % "I don't know how she swallowed a cow!" + "She swallowed the %s to catch the %s.\n" % ["cow", "goat"] + "She swallowed the %s to catch the %s.\n" % ["goat", "dog"] + "She swallowed the %s to catch the %s.\n" % ["dog", "cat"] + "She swallowed the %s to catch the %s.\n" % ["cat", "bird"] + "She swallowed the %s to catch the %s.\n" % ["bird", "spider that wriggled and jiggled and tickled inside her"] + "She swallowed the %s to catch the %s.\n" % ["spider", "fly"] + "%s\n" % "I don't know why she swallowed the fly. Perhaps she'll die." when 8 "I know an old lady who swallowed a %s.\n" % "horse" + "%s\n" % "She's dead, of course!" end
  36. case i when 1 "I know an old lady who

    swallowed a %s.\n" % "%s\n" %
  37. case i when 2 "I know an old lady who

    swallowed a %s.\n" % "%s\n" % "She swallowed the %s to catch the %s.\n" % "%s\n" %
  38. case i when 3 "I know an old lady who

    swallowed a %s.\n" % "%s\n" % "She swallowed the %s to catch the %s.\n" % "She swallowed the %s to catch the %s.\n" % "%s\n" %
  39. case i when 4 "I know an old lady who

    swallowed a %s.\n" % "%s\n" % "She swallowed the %s to catch the %s.\n" % "She swallowed the %s to catch the %s.\n" % "She swallowed the %s to catch the %s.\n" % "%s\n" %
  40. case i when 5 "I know an old lady who

    swallowed a %s.\n" % "%s\n" % "She swallowed the %s to catch the %s.\n" % "She swallowed the %s to catch the %s.\n" % "She swallowed the %s to catch the %s.\n" % "She swallowed the %s to catch the %s.\n" % "%s\n" %
  41. case i when 6 "I know an old lady who

    swallowed a %s.\n" % "%s\n" % "She swallowed the %s to catch the %s.\n" % "She swallowed the %s to catch the %s.\n" % "She swallowed the %s to catch the %s.\n" % "She swallowed the %s to catch the %s.\n" % "She swallowed the %s to catch the %s.\n" % "%s\n" %
  42. case i when 7 "I know an old lady who

    swallowed a %s.\n" % "%s\n" % "She swallowed the %s to catch the %s.\n" % "She swallowed the %s to catch the %s.\n" % "She swallowed the %s to catch the %s.\n" % "She swallowed the %s to catch the %s.\n" % "She swallowed the %s to catch the %s.\n" % "She swallowed the %s to catch the %s.\n" % "%s\n" %
  43. case i when 8 "I know an old lady who

    swallowed a %s.\n" % "%s\n" %
  44. "She swallowed the cow to catch the goat.\n" + "She

    swallowed the goat to catch the dog.\n" + "She swallowed the dog to catch the cat.\n" + "She swallowed the cat to catch the bird.\n" + "She swallowed the bird to catch the spider.\n" + "She swallowed the spider to catch the fly.\n" +
  45. She swallowed the cow to catch the goat. She swallowed

    the goat to catch the dog. She swallowed the dog to catch the cat. She swallowed the cat to catch the bird. She swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her. She swallowed the spider to catch the fly.
  46. class Song DATA = [ ["horse"], ["cow"], ["goat"], ["dog"], ["cat"],

    ["bird"], ["spider", "that wriggled ..."], ["fly"], ] end
  47. class Song DATA = [...] attr_reader :critters def initialize @critters

    = DATA.map {|row| Critter.new(*row) } end end
  48. def motivation(predator, prey) "She swallowed the %s to catch the

    %s." % [ predator.name, [ prey.name, prey.qualifier, ].compact.join(" "), ] end
  49. class Critter < Struct.new(:name, :qualifier) end class Song # ...

    def motivation(predator, prey) "She swallowed the %s to catch the %s." % [ predator.name, [ prey.name, prey.qualifier, ].compact.join(" "), ] end # ... end
  50. def motivation(predator, prey) "She swallowed the %s to catch the

    %s." % [ predator.name, [ prey.name, prey.qualifier, ].compact.join(" "), ] end
  51. def motivation(predator, prey) "She swallowed the %s to catch the

    %s." % [ predator.name, [ prey.name, prey.qualifier, ].compact.join(" "), ] end
  52. def motivation(predator, prey) "She swallowed the %s to catch the

    %s." % [ predator.name, [ prey.name, prey.qualifier, ].compact.join(" "), ] end TMI
  53. "%s\n" % "I don't know why she swallowed the fly.

    when 4 "I know an old lady who swallowed a %s.\n" % "cat"+ "%s\n" % "Imagine that, to swallow a cat!" + "She swallowed the %s to catch the %s.\n" % ["cat", "bird"] + "She swallowed the %s to catch the %s.\n" % ["bird", "spider that wriggled and jiggle "She swallowed the %s to catch the %s.\n" % ["spider", "fly"] + "%s\n" % "I don't know why she swallowed the fly. when 5 "I know an old lady who swallowed a %s.\n" % "dog" + "%s\n" % "What a hog, to swallow a dog!" + "She swallowed the %s to catch the %s.\n" % ["dog", "cat"] + "She swallowed the %s to catch the %s.\n" % ["cat", "bird"] + "She swallowed the %s to catch the %s.\n" % ["bird", "spider that wriggled and jiggle "She swallowed the %s to catch the %s.\n" % ["spider", "fly"] + "%s\n" % "I don't know why she swallowed the fly. when 6 "I know an old lady who swallowed a %s.\n" % "goat" + "%s\n" % "Just opened her throat and swallowed a g "She swallowed the %s to catch the %s.\n" % ["goat", "dog"] + "She swallowed the %s to catch the %s.\n" % ["dog", "cat"] + "She swallowed the %s to catch the %s.\n" % ["cat", "bird"] + "She swallowed the %s to catch the %s.\n" % ["bird", "spider that wriggled and jiggle
  54. "%s\n" % "I don't know why she swallowed the fly.

    when 4 "I know an old lady who swallowed a %s.\n" % "cat"+ "%s\n" % "Imagine that, to swallow a cat!" + "She swallowed the %s to catch the %s.\n" % ["cat", "bird"] + "She swallowed the %s to catch the %s.\n" % ["bird", "spider that wriggled and jiggle "She swallowed the %s to catch the %s.\n" % ["spider", "fly"] + "%s\n" % "I don't know why she swallowed the fly. when 5 "I know an old lady who swallowed a %s.\n" % "dog" + "%s\n" % "What a hog, to swallow a dog!" + "She swallowed the %s to catch the %s.\n" % ["dog", "cat"] + "She swallowed the %s to catch the %s.\n" % ["cat", "bird"] + "She swallowed the %s to catch the %s.\n" % ["bird", "spider that wriggled and jiggle "She swallowed the %s to catch the %s.\n" % ["spider", "fly"] + "%s\n" % "I don't know why she swallowed the fly. when 6 "I know an old lady who swallowed a %s.\n" % "goat" + "%s\n" % "Just opened her throat and swallowed a g "She swallowed the %s to catch the %s.\n" % ["goat", "dog"] + "She swallowed the %s to catch the %s.\n" % ["dog", "cat"] + "She swallowed the %s to catch the %s.\n" % ["cat", "bird"] + "She swallowed the %s to catch the %s.\n" % ["bird", "spider that wriggled and jiggle
  55. "%s\n" % "I don't know why she swallowed the fly.

    when 4 "I know an old lady who swallowed a %s.\n" % "cat"+ "%s\n" % "Imagine that, to swallow a cat!" + "%s\n" % chain(4) + "%s\n" % "I don't know why she swallowed the fly. when 5 "I know an old lady who swallowed a %s.\n" % "dog" + "%s\n" % "What a hog, to swallow a dog!" + "%s\n" % chain(5) + "%s\n" % "I don't know why she swallowed the fly. when 6 "I know an old lady who swallowed a %s.\n" % "goat" + "%s\n" % "Just opened her throat and swallowed a g "%s\n" % chain(6) + "%s\n" % "I don't know why she swallowed the fly. when 7 "I know an old lady who swallowed a %s.\n" % "cow" + "%s\n" % "I don't know how she swallowed a cow!" + "%s\n" % chain(7) + "%s\n" % "I don't know why she swallowed the fly. when 8 "I know an old lady who swallowed a %s.\n" % "horse" +
  56. case i when 1 "I know an old lady who

    swallowed a %s.\n" % "fly" + "%s\n" % "I don't know why she swallowed the fly. Perhaps she'll die." when 2 "I know an old lady who swallowed a %s.\n" % "spider" + "%s\n" % "It wriggled and jiggled and tickled inside her." + "She swallowed the %s to catch the %s.\n" % ["spider", "fly"] + "%s\n" % "I don't know why she swallowed the fly. Perhaps she'll die." when 3 "I know an old lady who swallowed a %s.\n" % "bird" + "%s\n" % "How absurd to swallow a bird!" + "She swallowed the %s to catch the %s.\n" % ["bird", "spider that wriggled and jiggled and tickled inside her"] + "She swallowed the %s to catch the %s.\n" % ["spider", "fly"] + "%s\n" % "I don't know why she swallowed the fly. Perhaps she'll die." when 4 "I know an old lady who swallowed a %s.\n" % "cat"+ "%s\n" % "Imagine that, to swallow a cat!" + "She swallowed the %s to catch the %s.\n" % ["cat", "bird"] + "She swallowed the %s to catch the %s.\n" % ["bird", "spider that wriggled and jiggled and tickled inside her"] + "She swallowed the %s to catch the %s.\n" % ["spider", "fly"] + "%s\n" % "I don't know why she swallowed the fly. Perhaps she'll die." when 5 "I know an old lady who swallowed a %s.\n" % "dog" + "%s\n" % "What a hog, to swallow a dog!" + "She swallowed the %s to catch the %s.\n" % ["dog", "cat"] + "She swallowed the %s to catch the %s.\n" % ["cat", "bird"] + "She swallowed the %s to catch the %s.\n" % ["bird", "spider that wriggled and jiggled and tickled inside her"] + "She swallowed the %s to catch the %s.\n" % ["spider", "fly"] + "%s\n" % "I don't know why she swallowed the fly. Perhaps she'll die." when 6 "I know an old lady who swallowed a %s.\n" % "goat" + "%s\n" % "Just opened her throat and swallowed a goat!" + "She swallowed the %s to catch the %s.\n" % ["goat", "dog"] + "She swallowed the %s to catch the %s.\n" % ["dog", "cat"] + "She swallowed the %s to catch the %s.\n" % ["cat", "bird"] + "She swallowed the %s to catch the %s.\n" % ["bird", "spider that wriggled and jiggled and tickled inside her"] + "She swallowed the %s to catch the %s.\n" % ["spider", "fly"] + "%s\n" % "I don't know why she swallowed the fly. Perhaps she'll die." when 7 "I know an old lady who swallowed a %s.\n" % "cow" + "%s\n" % "I don't know how she swallowed a cow!" + "She swallowed the %s to catch the %s.\n" % ["cow", "goat"] + "She swallowed the %s to catch the %s.\n" % ["goat", "dog"] + "She swallowed the %s to catch the %s.\n" % ["dog", "cat"] + "She swallowed the %s to catch the %s.\n" % ["cat", "bird"] + "She swallowed the %s to catch the %s.\n" % ["bird", "spider that wriggled and jiggled and tickled inside her"] + "She swallowed the %s to catch the %s.\n" % ["spider", "fly"] + "%s\n" % "I don't know why she swallowed the fly. Perhaps she'll die." when 8 "I know an old lady who swallowed a %s.\n" % "horse" + "%s\n" % "She's dead, of course!" end
  57. case i when 1 "I know an old lady who

    swallowed a %s.\n" % "fly" + "%s\n" % "I don't know why she swallowed the fly. Perhaps she'll die." when 2 "I know an old lady who swallowed a %s.\n" % "spider" + "%s\n" % "It wriggled and jiggled and tickled inside her." + "%s\n" % chain(2) + "%s\n" % "I don't know why she swallowed the fly. Perhaps she'll die." when 3 "I know an old lady who swallowed a %s.\n" % "bird" + "%s\n" % "How absurd to swallow a bird!" + "%s\n" % chain(3) + "%s\n" % "I don't know why she swallowed the fly. Perhaps she'll die." when 4 "I know an old lady who swallowed a %s.\n" % "cat"+ "%s\n" % "Imagine that, to swallow a cat!" + "%s\n" % chain(4) + "%s\n" % "I don't know why she swallowed the fly. Perhaps she'll die." when 5 "I know an old lady who swallowed a %s.\n" % "dog" + "%s\n" % "What a hog, to swallow a dog!" + "%s\n" % chain(5) + "%s\n" % "I don't know why she swallowed the fly. Perhaps she'll die." when 6 "I know an old lady who swallowed a %s.\n" % "goat" + "%s\n" % "Just opened her throat and swallowed a goat!" + "%s\n" % chain(6) + "%s\n" % "I don't know why she swallowed the fly. Perhaps she'll die." when 7 "I know an old lady who swallowed a %s.\n" % "cow" + "%s\n" % "I don't know how she swallowed a cow!" + "%s\n" % chain(7) + "%s\n" % "I don't know why she swallowed the fly. Perhaps she'll die." when 8 "I know an old lady who swallowed a %s.\n" % "horse" + "%s\n" % "She's dead, of course!" end
  58. class Critter < Struct.new(:name, :qualifier) def epithet [name, qualifier].compact.join(" ")

    end end class Song DATA = [ ["horse"], ["cow"], ["goat"], ["dog"], ["cat"], ["bird"], ["spider", "that wriggled and jiggled and tickled inside her"], ["fly"], ] attr_reader :critters def initialize @critters = DATA.map {|row| Critter.new(*row)} end def lyrics (1..8).map {|i| verse(i)}.join("\n") end private def chain(i) critters.last(i).each_cons(2).map {|pair| motivation(*pair) }.join("\n") end def motivation(predator, prey) "She swallowed the %s to catch the %s." % [ predator.name, prey.epithet, ] end # ... end class Song # continued ... def verse(i) case i when 1 "I know an old lady who swallowed a %s.\n" % "fly" + "%s\n" % "I don't know why she swallowed the fly. Perhaps she'll die." when 2 "I know an old lady who swallowed a %s.\n" % "spider" + "%s\n" % "It wriggled and jiggled and tickled inside her." + "%s\n" % chain(2) + "%s\n" % "I don't know why she swallowed the fly. Perhaps she'll die." when 3 "I know an old lady who swallowed a %s.\n" % "bird" + "%s\n" % "How absurd to swallow a bird!" + "%s\n" % chain(3) + "%s\n" % "I don't know why she swallowed the fly. Perhaps she'll die." when 4 "I know an old lady who swallowed a %s.\n" % "cat"+ "%s\n" % "Imagine that, to swallow a cat!" + "%s\n" % chain(4) + "%s\n" % "I don't know why she swallowed the fly. Perhaps she'll die." when 5 "I know an old lady who swallowed a %s.\n" % "dog" + "%s\n" % "What a hog, to swallow a dog!" + "%s\n" % chain(5) + "%s\n" % "I don't know why she swallowed the fly. Perhaps she'll die." when 6 "I know an old lady who swallowed a %s.\n" % "goat" + "%s\n" % "Just opened her throat and swallowed a goat!" + "%s\n" % chain(6) + "%s\n" % "I don't know why she swallowed the fly. Perhaps she'll die." when 7 "I know an old lady who swallowed a %s.\n" % "cow" + "%s\n" % "I don't know how she swallowed a cow!" + "%s\n" % chain(7) + "%s\n" % "I don't know why she swallowed the fly. Perhaps she'll die." when 8 "I know an old lady who swallowed a %s.\n" % "horse" + "%s\n" % "She's dead, of course!" end end end
  59. when 5 "I know an old lady..." % "dog" +

    "%s\n" % "What a hog, to swallow a dog!" + "%s\n" % chain(5) + "%s\n" % "I don't know why..." when 6 "I know an old lady..." % "goat" + "%s\n" % "Just opened her throat and swallowed a goat!" + "%s\n" % chain(6) + "%s\n" % "I don't know why..." when 7 "I know an old lady..." % "cow" + "%s\n" % "I don't know how she swallowed a cow!" + "%s\n" % chain(7) + "%s\n" % "I don't know why..." when 8
  60. when 5 "I know an old lady..." % "dog" +

    "%s\n" % "What a hog, to swallow a dog!" + "%s\n" % chain(5) + "%s\n" % "I don't know why..." when 6 "I know an old lady..." % "goat" + "%s\n" % "Just opened her throat and swallowed a goat!" + "%s\n" % chain(6) + "%s\n" % "I don't know why..." when 7 "I know an old lady..." % "cow" + "%s\n" % "I don't know how she swallowed a cow!" + "%s\n" % chain(7) + "%s\n" % "I don't know why..." when 8
  61. when 5 "I know an old lady..." % "dog" +

    "%s\n" % "What a hog, to swallow a dog!" + "%s\n" % chain(5) + "%s\n" % "I don't know why..." when 6 "I know an old lady..." % "goat" + "%s\n" % "Just opened her throat and swallowed a goat!" + "%s\n" % chain(6) + "%s\n" % "I don't know why..." when 7 "I know an old lady..." % "cow" + "%s\n" % "I don't know how she swallowed a cow!" + "%s\n" % chain(7) + "%s\n" % "I don't know why..." when 8
  62. when 5 "I know an old lady..." % "dog" +

    "%s\n" % "What a hog, to swallow a dog!" + "%s\n" % chain(i) + "%s\n" % "I don't know why..." when 6 "I know an old lady..." % "goat" + "%s\n" % "Just opened her throat and swallowed a goat!" + "%s\n" % chain(i) + "%s\n" % "I don't know why..." when 7 "I know an old lady..." % "cow" + "%s\n" % "I don't know how she swallowed a cow!" + "%s\n" % chain(i) + "%s\n" % "I don't know why..." when 8
  63. when 5 "I know an old lady..." % "dog" +

    "%s\n" % "What a hog, to swallow a dog!" + "%s\n" % chain(i) + "%s\n" % "I don't know why..." when 6 "I know an old lady..." % "goat" + "%s\n" % "Just opened her throat and swallowed a goat!" + "%s\n" % chain(i) + "%s\n" % "I don't know why..." when 7 "I know an old lady..." % "cow" + "%s\n" % "I don't know how she swallowed a cow!" + "%s\n" % chain(i) + "%s\n" % "I don't know why..." when 8
  64. when 5 "I know an old lady..." % "dog" +

    "%s\n" % "What a hog, to swallow a dog!" + "%s\n" % chain(i) + "%s\n" % "I don't know why..." when 6 "I know an old lady..." % "goat" + "%s\n" % "Just opened her throat and swallowed a goat!" + "%s\n" % chain(i) + "%s\n" % "I don't know why..." when 7 "I know an old lady..." % "cow" + "%s\n" % "I don't know how she swallowed a cow!" + "%s\n" % chain(i) + "%s\n" % "I don't know why..." when 8
  65. when 5 "I know an old lady..." % "dog" +

    "%s\n" % "What a hog, to swallow a dog!" + "%s\n" % chain(i) + "%s\n" % "I don't know why..." when 6 "I know an old lady..." % "goat" + "%s\n" % "Just opened her throat and swallowed a goat!" + "%s\n" % chain(i) + "%s\n" % "I don't know why..." when 7 "I know an old lady..." % "cow" + "%s\n" % "I don't know how she swallowed a cow!" + "%s\n" % chain(i) + "%s\n" % "I don't know why..." when 8
  66. when 5 "I know an old lady..." % "dog" +

    "%s\n" % "What a hog, to swallow a dog!" + "%s\n" % chain(i) + "%s\n" % "I don't know why..." when 6 "I know an old lady..." % "goat" + "%s\n" % "Just opened her throat and swallowed a goat!" + "%s\n" % chain(i) + "%s\n" % "I don't know why..." when 7 "I know an old lady..." % "cow" + "%s\n" % "I don't know how she swallowed a cow!" + "%s\n" % chain(i) + "%s\n" % "I don't know why..." when 8
  67. when 5 "I know an old lady..." % critters.last(i).first.name +

    "%s\n" % "What a hog, to swallow a dog!" + "%s\n" % chain(i) + "%s\n" % "I don't know why..." when 6 "I know an old lady..." % critters.last(i).first.name + "%s\n" % "Just opened her throat and swallowed a goat!" + "%s\n" % chain(i) + "%s\n" % "I don't know why..." when 7 "I know an old lady..." % critters.last(i).first.name + "%s\n" % "I don't know how she swallowed a cow!" + "%s\n" % chain(i) + "%s\n" % "I don't know why..." when 8
  68. when 5 "I know an old lady..." % critters.last(i).first.name +

    "%s\n" % "What a hog, to swallow a dog!" + "%s\n" % chain(i) + "%s\n" % "I don't know why..." when 6 "I know an old lady..." % critters.last(i).first.name + "%s\n" % "Just opened her throat and swallowed a goat!" + "%s\n" % chain(i) + "%s\n" % "I don't know why..." when 7 "I know an old lady..." % critters.last(i).first.name + "%s\n" % "I don't know how she swallowed a cow!" + "%s\n" % chain(i) + "%s\n" % "I don't know why..." when 8
  69. when 5 "I know an old lady..." % critters.last(i).first.name +

    "%s\n" % "What a hog, to swallow a dog!" + "%s\n" % chain(i) + "%s\n" % "I don't know why..." when 6 "I know an old lady..." % critters.last(i).first.name + "%s\n" % "Just opened her throat and swallowed a goat!" + "%s\n" % chain(i) + "%s\n" % "I don't know why..." when 7 "I know an old lady..." % critters.last(i).first.name + "%s\n" % "I don't know how she swallowed a cow!" + "%s\n" % chain(i) + "%s\n" % "I don't know why..." when 8
  70. I know an old lady who swallowed a . fly

    I don't know why she swallowed a fly. Perhaps she'll die.
  71. I know an old lady who swallowed a . spider

    It wriggled and jiggled and tickled inside her.
  72. I know an old lady who swallowed a . bird

    How absurd to swallow a bird!
  73. I know an old lady who swallowed a . cat

    Imagine that, to swallow a cat!
  74. I know an old lady who swallowed a . dog

    What a hog, to swallow a dog!
  75. I know an old lady who swallowed a . goat

    Just opened her throat and swallowed a goat!
  76. I know an old lady who swallowed a . cow

    I don't know how she swallowed a cow!
  77. class Song DATA = [ ["horse"], ["cow"], ["goat"], ["dog"], ["cat"],

    ["bird"], ["spider", "that wriggled ..."], ["fly"], ] end
  78. class Song DATA = [ ["horse", nil, "She's dead, of

    course!"], ["cow", nil, "I don't know how..."], ["goat", nil, "Just opened her throat..."], ["dog", nil, "What a hog, to swallow a dog!"], ["cat", nil, "Imagine that, to swallow a cat!"], ["bird"], ["spider", "that wriggled...", "It wriggled..."], ["fly", nil, "I don't know why..."], ] end
  79. when 5 "I know an old lady..." % critters.last(i).first.name +

    "%s\n" % "What a hog, to swallow a dog!" + "%s\n" % chain(i) + "%s\n" % "I don't know why she swallowed the fly..." when 6 "I know an old lady..." % critters.last(i).first.name + "%s\n" % "Just opened her throat and swallowed a goat!" + "%s\n" % chain(i) + "%s\n" % "I don't know why she swallowed the fly..." when 7 "I know an old lady..." % critters.last(i).first.name + "%s\n" % "I don't know how she swallowed a cow!" + "%s\n" % chain(i) + "%s\n" % "I don't know why she swallowed the fly..." when 8
  80. when 5 "I know an old lady..." % critters.last(i).first.name +

    "%s\n" % critters.last(i).first.aside + "%s\n" % chain(i) + "%s\n" % "I don't know why she swallowed the fly..." when 6 "I know an old lady..." % critters.last(i).first.name + "%s\n" % critters.last(i).first.aside + "%s\n" % chain(i) + "%s\n" % "I don't know why she swallowed the fly..." when 7 "I know an old lady..." % critters.last(i).first.name + "%s\n" % critters.last(i).first.aside + "%s\n" % chain(i) + "%s\n" % "I don't know why she swallowed the fly..." when 8
  81. when 5 "I know an old lady..." % critters.last(i).first.name +

    "%s\n" % critters.last(i).first.aside + "%s\n" % chain(i) + "%s\n" % "I don't know why she swallowed the fly..." when 6 "I know an old lady..." % critters.last(i).first.name + "%s\n" % critters.last(i).first.aside + "%s\n" % chain(i) + "%s\n" % "I don't know why she swallowed the fly..." when 7 "I know an old lady..." % critters.last(i).first.name + "%s\n" % critters.last(i).first.aside + "%s\n" % chain(i) + "%s\n" % "I don't know why she swallowed the fly..." when 8
  82. when 4 "I know an old lady..." % critters.last(i).first.name +

    "%s\n" % critters.last(i).first.aside + "%s\n" % chain(i) + "%s\n" % "I don't know why she swallowed the fly. Perhaps she'll die." when 5 "I know an old lady..." % critters.last(i).first.name + "%s\n" % critters.last(i).first.aside + "%s\n" % chain(i) + "%s\n" % "I don't know why she swallowed the fly. Perhaps she'll die." when 6 "I know an old lady..." % critters.last(i).first.name + "%s\n" % critters.last(i).first.aside + "%s\n" % chain(i) + "%s\n" % "I don't know why she swallowed the fly. Perhaps she'll die." when 7 "I know an old lady..." % critters.last(i).first.name + "%s\n" % critters.last(i).first.aside + "%s\n" % chain(i) + "%s\n" % "I don't know why she swallowed the fly. Perhaps she'll die." when 8
  83. case i when 1, 8 "I know an old lady..."

    % critters.last(i).first.name + "%s\n" % "I don't know why she swallowed the fly. Perhaps..." else "I know an old lady..." % critters.last(i).first.name + "%s\n" % critters.last(i).first.aside + "%s\n" % chain(i) + "%s\n" % "I don't know why she swallowed the fly. Perhaps..." end
  84. <<-SONG I know an old lady who swallowed a fly.

    I don't know why she swallowed the fly. Perhaps she'll die. I know an old lady who swallowed a spider. It wriggled and jiggled and tickled inside her. She swallowed the spider to catch the fly. I don't know why she swallowed the fly. Perhaps she'll die. I know an old lady who swallowed a bird. How absurd to swallow a bird! She swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her. She swallowed the spider to catch the fly. I don't know why she swallowed the fly. Perhaps she'll die. I know an old lady who swallowed a cat. Imagine that, to swallow a cat! She swallowed the cat to catch the bird. She swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her. She swallowed the spider to catch the fly. I don't know why she swallowed the fly. Perhaps she'll die. I know an old lady who swallowed a dog. What a hog, to swallow a dog! She swallowed the dog to catch the cat. She swallowed the cat to catch the bird. She swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her. She swallowed the spider to catch the fly. I don't know why she swallowed the fly. Perhaps she'll die. I know an old lady who swallowed a goat. Just opened her throat and swallowed a goat! She swallowed the goat to catch the dog. She swallowed the dog to catch the cat. She swallowed the cat to catch the bird. She swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her. She swallowed the spider to catch the fly. I don't know why she swallowed the fly. Perhaps she'll die. I know an old lady who swallowed a cow. I don't know how she swallowed a cow! She swallowed the cow to catch the goat. She swallowed the goat to catch the dog. She swallowed the dog to catch the cat. She swallowed the cat to catch the bird. She swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her. She swallowed the spider to catch the fly. I don't know why she swallowed the fly. Perhaps she'll die. I know an old lady who swallowed a horse. She's dead, of course! SONG
  85. case i when 1 "I know an old lady who

    swallowed a fly.\n" + "I don't know why she swallowed the fly. Perhaps she'll die.\n" when 2 "I know an old lady who swallowed a spider.\n" + "It wriggled and jiggled and tickled inside her.\n" + "She swallowed the spider to catch the fly.\n" + "I don't know why she swallowed the fly. Perhaps she'll die.\n" when 3 "I know an old lady who swallowed a bird.\n" + "How absurd to swallow a bird!\n" + "She swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her.\n" + "She swallowed the spider to catch the fly.\n" + "I don't know why she swallowed the fly. Perhaps she'll die.\n" when 4 "I know an old lady who swallowed a cat.\n" + "Imagine that, to swallow a cat!\n" + "She swallowed the cat to catch the bird.\n" + "She swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her.\n" + "She swallowed the spider to catch the fly.\n" + "I don't know why she swallowed the fly. Perhaps she'll die.\n" when 5 "I know an old lady who swallowed a dog.\n" + "What a hog, to swallow a dog!\n" + "She swallowed the dog to catch the cat.\n" + "She swallowed the cat to catch the bird.\n" + "She swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her.\n" + "She swallowed the spider to catch the fly.\n" + "I don't know why she swallowed the fly. Perhaps she'll die.\n" when 6 "I know an old lady who swallowed a goat.\n" + "Just opened her throat and swallowed a goat!\n" + "She swallowed the goat to catch the dog.\n" + "She swallowed the dog to catch the cat.\n" + "She swallowed the cat to catch the bird.\n" + "She swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her.\n" + "She swallowed the spider to catch the fly.\n" + "I don't know why she swallowed the fly. Perhaps she'll die.\n" when 7 "I know an old lady who swallowed a cow.\n" + "I don't know how she swallowed a cow!\n" + "She swallowed the cow to catch the goat.\n" + "She swallowed the goat to catch the dog.\n" + "She swallowed the dog to catch the cat.\n" + "She swallowed the cat to catch the bird.\n" + "She swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her.\n" + "She swallowed the spider to catch the fly.\n" + "I don't know why she swallowed the fly. Perhaps she'll die.\n" when 8 "I know an old lady who swallowed a horse.\n" + "She's dead, of course!\n" end
  86. case i when 1 "I know an old lady who

    swallowed a %s.\n" % "fly" + "%s\n" % "I don't know why she swallowed the fly. Perhaps she'll die." when 2 "I know an old lady who swallowed a %s.\n" % "spider" + "%s\n" % "It wriggled and jiggled and tickled inside her." + "She swallowed the %s to catch the %s.\n" % ["spider", "fly"] + "%s\n" % "I don't know why she swallowed the fly. Perhaps she'll die." when 3 "I know an old lady who swallowed a %s.\n" % "bird" + "%s\n" % "How absurd to swallow a bird!" + "She swallowed the %s to catch the %s.\n" % ["bird", "spider that wriggled and jiggled and tickled inside her"] + "She swallowed the %s to catch the %s.\n" % ["spider", "fly"] + "%s\n" % "I don't know why she swallowed the fly. Perhaps she'll die." when 4 "I know an old lady who swallowed a %s.\n" % "cat"+ "%s\n" % "Imagine that, to swallow a cat!" + "She swallowed the %s to catch the %s.\n" % ["cat", "bird"] + "She swallowed the %s to catch the %s.\n" % ["bird", "spider that wriggled and jiggled and tickled inside her"] + "She swallowed the %s to catch the %s.\n" % ["spider", "fly"] + "%s\n" % "I don't know why she swallowed the fly. Perhaps she'll die." when 5 "I know an old lady who swallowed a %s.\n" % "dog" + "%s\n" % "What a hog, to swallow a dog!" + "She swallowed the %s to catch the %s.\n" % ["dog", "cat"] + "She swallowed the %s to catch the %s.\n" % ["cat", "bird"] + "She swallowed the %s to catch the %s.\n" % ["bird", "spider that wriggled and jiggled and tickled inside her"] + "She swallowed the %s to catch the %s.\n" % ["spider", "fly"] + "%s\n" % "I don't know why she swallowed the fly. Perhaps she'll die." when 6 "I know an old lady who swallowed a %s.\n" % "goat" + "%s\n" % "Just opened her throat and swallowed a goat!" + "She swallowed the %s to catch the %s.\n" % ["goat", "dog"] + "She swallowed the %s to catch the %s.\n" % ["dog", "cat"] + "She swallowed the %s to catch the %s.\n" % ["cat", "bird"] + "She swallowed the %s to catch the %s.\n" % ["bird", "spider that wriggled and jiggled and tickled inside her"] + "She swallowed the %s to catch the %s.\n" % ["spider", "fly"] + "%s\n" % "I don't know why she swallowed the fly. Perhaps she'll die." when 7 "I know an old lady who swallowed a %s.\n" % "cow" + "%s\n" % "I don't know how she swallowed a cow!" + "She swallowed the %s to catch the %s.\n" % ["cow", "goat"] + "She swallowed the %s to catch the %s.\n" % ["goat", "dog"] + "She swallowed the %s to catch the %s.\n" % ["dog", "cat"] + "She swallowed the %s to catch the %s.\n" % ["cat", "bird"] + "She swallowed the %s to catch the %s.\n" % ["bird", "spider that wriggled and jiggled and tickled inside her"] + "She swallowed the %s to catch the %s.\n" % ["spider", "fly"] + "%s\n" % "I don't know why she swallowed the fly. Perhaps she'll die." when 8 "I know an old lady who swallowed a %s.\n" % "horse" + "%s\n" % "She's dead, of course!" end
  87. def verse(i) case i when 1 "I know an old

    lady who swallowed a %s.\n" % "fly" + "%s\n" % "I don't know why she swallowed the fly. Perhaps she'll die." when 2 "I know an old lady who swallowed a %s.\n" % "spider" + "%s\n" % "It wriggled and jiggled and tickled inside her." + "%s\n" % chain(2) + "%s\n" % "I don't know why she swallowed the fly. Perhaps she'll die." when 3 "I know an old lady who swallowed a %s.\n" % "bird" + "%s\n" % "How absurd to swallow a bird!" + "%s\n" % chain(3) + "%s\n" % "I don't know why she swallowed the fly. Perhaps she'll die." when 4 "I know an old lady who swallowed a %s.\n" % "cat"+ "%s\n" % "Imagine that, to swallow a cat!" + "%s\n" % chain(4) + "%s\n" % "I don't know why she swallowed the fly. Perhaps she'll die." when 5 "I know an old lady who swallowed a %s.\n" % "dog" + "%s\n" % "What a hog, to swallow a dog!" + "%s\n" % chain(5) + "%s\n" % "I don't know why she swallowed the fly. Perhaps she'll die." when 6 "I know an old lady who swallowed a %s.\n" % "goat" + "%s\n" % "Just opened her throat and swallowed a goat!" + "%s\n" % chain(6) + "%s\n" % "I don't know why she swallowed the fly. Perhaps she'll die." when 7 "I know an old lady who swallowed a %s.\n" % "cow" + "%s\n" % "I don't know how she swallowed a cow!" + "%s\n" % chain(7) + "%s\n" % "I don't know why she swallowed the fly. Perhaps she'll die." when 8 "I know an old lady who swallowed a %s.\n" % "horse" + "%s\n" % "She's dead, of course!" end end def chain(i) critters.last(i).each_cons(2).map {|pair| motivation(*pair) }.join("\n") end def motivation(predator, prey) "She swallowed the %s to catch the %s." % [ predator.name, prey.epithet, ] end
  88. case i when 1 "I know an old lady who

    swallowed a %s.\n" % "fly" + "%s\n" % "I don't know why she swallowed the fly. Perhaps she'll die." when 2 "I know an old lady who swallowed a %s.\n" % "spider" + "%s\n" % "It wriggled and jiggled and tickled inside her." + "%s\n" % chain(2) + "%s\n" % "I don't know why she swallowed the fly. Perhaps she'll die." when 3 "I know an old lady who swallowed a %s.\n" % "bird" + "%s\n" % "How absurd to swallow a bird!" + "%s\n" % chain(3) + "%s\n" % "I don't know why she swallowed the fly. Perhaps she'll die." when 4 "I know an old lady who swallowed a %s.\n" % "cat"+ "%s\n" % "Imagine that, to swallow a cat!" + "%s\n" % chain(4) + "%s\n" % "I don't know why she swallowed the fly. Perhaps she'll die." when 5 "I know an old lady who swallowed a %s.\n" % "dog" + "%s\n" % "What a hog, to swallow a dog!" + "%s\n" % chain(5) + "%s\n" % "I don't know why she swallowed the fly. Perhaps she'll die." when 6 "I know an old lady who swallowed a %s.\n" % "goat" + "%s\n" % "Just opened her throat and swallowed a goat!" + "%s\n" % chain(6) + "%s\n" % "I don't know why she swallowed the fly. Perhaps she'll die." when 7 "I know an old lady who swallowed a %s.\n" % "cow" + "%s\n" % "I don't know how she swallowed a cow!" + "%s\n" % chain(7) + "%s\n" % "I don't know why she swallowed the fly. Perhaps she'll die." when 8 "I know an old lady who swallowed a %s.\n" % "horse" + "%s\n" % "She's dead, of course!" end
  89. case i when 1 "I know an old lady who

    swallowed a %s.\n" % critters.last(i).first.name + "%s\n" % critters.last(i).first.aside when 2 "I know an old lady who swallowed a %s.\n" % critters.last(i).first.name + "%s\n" % critters.last(i).first.aside + "%s\n" % chain(i) + "%s\n" % "I don't know why she swallowed the fly. Perhaps she'll die." when 3 "I know an old lady who swallowed a %s.\n" % critters.last(i).first.name + "%s\n" % critters.last(i).first.aside + "%s\n" % chain(i) + "%s\n" % "I don't know why she swallowed the fly. Perhaps she'll die." when 4 "I know an old lady who swallowed a %s.\n" % critters.last(i).first.name + "%s\n" % critters.last(i).first.aside + "%s\n" % chain(i) + "%s\n" % "I don't know why she swallowed the fly. Perhaps she'll die." when 5 "I know an old lady who swallowed a %s.\n" % critters.last(i).first.name + "%s\n" % critters.last(i).first.aside + "%s\n" % chain(i) + "%s\n" % "I don't know why she swallowed the fly. Perhaps she'll die." when 6 "I know an old lady who swallowed a %s.\n" % critters.last(i).first.name + "%s\n" % critters.last(i).first.aside + "%s\n" % chain(i) + "%s\n" % "I don't know why she swallowed the fly. Perhaps she'll die." when 7 "I know an old lady who swallowed a %s.\n" % critters.last(i).first.name + "%s\n" % critters.last(i).first.aside + "%s\n" % chain(i) + "%s\n" % "I don't know why she swallowed the fly. Perhaps she'll die." when 8 "I know an old lady who swallowed a %s.\n" % critters.last(i).first.name + "%s\n" % critters.last(i).first.aside end
  90. case i when 1, 8 "I know an old lady

    who swallowed a %s.\n" % critters.last(i).first.name + "%s\n" % critters.last(i).first.aside else "I know an old lady who swallowed a %s.\n" % critters.last(i).first.name + "%s\n" % critters.last(i).first.aside + "%s\n" % chain(i) + "%s\n" % "I don't know why she swallowed the fly. Perhaps she'll die." end
  91. class Song def initialize # ... def lyrics # ...

    private def verse(i) # ... def chain(i) # ... def motivation(predator, prey) # ... end
  92. class Song def initialize # ... def lyrics # ...

    private def verse(i) # ... def chain(i) # ... def motivation(predator, prey) # ... end
  93. class Song def initialize # ... def lyrics # ...

    end class Verse def verse(i) # ... def chain(i) # ... def motivation(predator, prey) # ... end
  94. class Song def initialize # ... def lyrics # ...

    private def verse(i) # ... def chain(i) # ... def motivation(predator, prey) # ... end class Verse # ... end
  95. class Verse def verse(i) # ... def chain(i) # ...

    def motivation(predator, prey) # ... end
  96. class Verse def verse(i) # ... def chain(i) # ...

    def motivation(predator, prey) # ... end
  97. class Verse def initialize(critters) # ... def verse(i) # ...

    def chain(i) # ... def motivation(predator, prey) # ... end
  98. class Verse attr_reader :critters def initialize(critters) # ... def verse(i)

    # ... def chain(i) # ... def motivation(predator, prey) # ... end
  99. class Verse attr_reader :critters def initialize(critters) # ... def verse(i)

    # ... def chain(i) # ... def motivation(predator, prey) # ... end
  100. class Verse attr_reader :critters def initialize(critters) # ... def verse

    # ... def chain # ... def motivation(predator, prey) # ... end
  101. class Verse attr_reader :critters, :i def initialize(critters) # ... def

    to_s # ... def chain # ... def motivation(predator, prey) # ... end
  102. class Verse attr_reader :critters, i def initialize(critters) # ... def

    to_s # ... def chain # ... def motivation(predator, prey) # ... end
  103. class Verse attr_reader :critters, i def initialize(critters) # ... def

    to_s # ... private def chain # ... def motivation(predator, prey) # ... end
  104. class Song def initialize # ... def lyrics (1..8).map {|i|

    verse(i) }.join("\n") end private def verse(i) # ... def chain(i) # ... def motivation(predator, prey) # ... end
  105. class Song def initialize # ... def lyrics (1..8).map {|i|

    verse(i) }.join("\n") end private def verse(i) # ... def chain(i) # ... def motivation(predator, prey) # ... end
  106. class Song def initialize # ... def lyrics (1..8).map {|i|

    Verse.new(critters.last(i)) }.join("\n") end private def verse(i) # ... def chain(i) # ... def motivation(predator, prey) # ... end
  107. class Song def initialize # ... def lyrics (1..8).map {|i|

    Verse.new(critters.last(i)) }.join("\n") end end
  108. class Verse attr_reader :critters, :i def initialize(critters) @critters = critters

    @i = critters.length end def to_s case i when 1, 8 "I know an old lady who swallowed a %s.\n" % critters.last(i).first.name + "%s\n" % critters.last(i).first.aside else "I know an old lady who swallowed a %s.\n" % critters.last(i).first.name + "%s\n" % critters.last(i).first.aside + "%s\n" % chain + "%s\n" % "I don't know why she swallowed the fly. Perhaps she'll die." end end private def chain critters.last(i).each_cons(2).map {|pair| motivation(*pair) }.join("\n") end def motivation(predator, prey) "She swallowed the %s to catch the %s." % [ predator.name, prey.epithet, ] end end class Critter < Struct.new(:name, :qualifier, :aside) def epithet [name, qualifier].compact.join(" ") end end class Song DATA = [ ["horse", nil, "She's dead, of course!"], ["cow", nil, "I don't know how she swallowed a cow!"], ["goat", nil, "Just opened her throat and swallowed a goat!"], ["dog", nil, "What a hog, to swallow a dog!"], ["cat", nil, "Imagine that, to swallow a cat!"], ["bird", nil, "How absurd to swallow a bird!"], [ "spider", "that wriggled and jiggled and tickled inside her", "It wriggled and jiggled and tickled inside her.", ], ["fly", nil, "I don't know why she swallowed the fly. Perhaps she'll die."], ] attr_reader :critters def initialize @critters = DATA.map {|row| Critter.new(*row)} end def lyrics (1..8).map {|i| Verse.new(critters.last(i)) }.join("\n") end end
  109. class Song DATA = [ ["horse", nil, "She's dead, of

    course!"], ["cow", nil, "I don't know how she swallowed a cow!"], ["goat", nil, "Just opened her throat and swallowed a goat!"], ["dog", nil, "What a hog, to swallow a dog!"], ["cat", nil, "Imagine that, to swallow a cat!"], ["bird", nil, "How absurd to swallow a bird!"], [ "spider", "that wriggled and jiggled and tickled inside her", "It wriggled and jiggled and tickled inside her.", ], ["fly", nil, "I don't know why she swallowed the fly. Perhaps she'll die."], ] attr_reader :critters def initialize @critters = DATA.map {|row| Critter.new(*row)} end def lyrics (1..8).map {|i| Verse.new(critters.last(i)) }.join("\n") end end
  110. class Verse attr_reader :critters, :i def initialize(critters) @critters = critters

    @i = critters.length end def to_s case i when 1, 8 "I know an old lady who swallowed a %s.\n" % critters.last(i).first.name + "%s\n" % critters.last(i).first.aside else "I know an old lady who swallowed a %s.\n" % critters.last(i).first.name + "%s\n" % critters.last(i).first.aside + "%s\n" % chain + "%s\n" % "I don't know why she swallowed the fly. Perhaps she'll die." end end private def chain critters.last(i).each_cons(2).map {|pair| motivation(*pair) }.join("\n") end def motivation(predator, prey) "She swallowed the %s to catch the %s." % [ predator.name, prey.epithet, ] end end
  111. case i when 1, 8 "I know an old lady..."

    % critters.last(i).first.name + "%s\n" % critters.last(i).first.aside else "I know an old lady..." % critters.last(i).first.name + "%s\n" % critters.last(i).first.aside + "%s\n" % chain + "%s\n" % "I don't know why she swallowed the fly. Perhaps she'll die." end
  112. case i when 1, 8 "I know an old lady..."

    % critters.last(i).first.name + "%s\n" % critters.last(i).first.aside else "I know an old lady..." % critters.last(i).first.name + "%s\n" % critters.last(i).first.aside + "%s\n" % chain + "%s\n" % "I don't know why she swallowed the fly. Perhaps she'll die." end
  113. case i when 1, 8 "I know an old lady..."

    % critters.last(i).first.name + "%s\n" % critters.last(i).first.aside else "I know an old lady..." % critters.last(i).first.name + "%s\n" % critters.last(i).first.aside + "%s\n" % chain + "%s\n" % "I don't know why she swallowed the fly. Perhaps she'll die." end
  114. case i when 1, 8 "" else "%s\n" % chain

    + "%s\n" % "I don't know why she swallowed..." end
  115. def summary case i when 1, 8 "" else "%s\n"

    % chain + "%s\n" % "I don't know why she swallowed..." end end
  116. def recap case i when 1, 8 "" else "%s\n"

    % chain + "%s\n" % "I don't know why she swallowed..." end end
  117. "I know an old lady who swallowed a %s.\n%s\n" %

    [ critters.last(i).first.name, critters.last(i).first.aside, ]
  118. def incident "I know an old lady who swallowed a

    %s.\n%s\n" % [ critters.last(i).first.name, critters.last(i).first.aside, ] end
  119. def incident "I know an old lady who swallowed a

    %s.\n%s\n" % [ critters.last(i).first.name, critters.last(i).first.aside, ] end def recap case i when 1, 8 "" else "%s\n" % chain + "%s\n" % "I don't know why she swallowed the fly..." end end
  120. def incident "I know an old lady who swallowed a

    %s.\n%s\n" % [ critters.last(i).first.name, critters.last(i).first.aside, ] end def chain critters.last(i).each_cons(2).map {|pair| motivation(*pair) }.join("\n") end
  121. def incident "I know an old lady who swallowed a

    %s.\n%s\n" % [ critters.first.name, critters.first.aside, ] end def chain critters.each_cons(2).map {|pair| motivation(*pair) }.join("\n") end
  122. attr_reader :critters, :i def initialize(critters) @critters = critters @i =

    critters.length end def to_s case i when 1, 8 # ... else # ... end end
  123. attr_reader :critters, :i def initialize(critters) @critters = critters @i =

    critters.length end def to_s case i when 1, 8 # ... else # ... end end
  124. attr_reader :critters def initialize(critters) @critters = critters end def to_s

    case critters.length when 1, 8 # ... else # ... end end
  125. attr_reader :critters def initialize(critters) @critters = critters end def incident

    "I know an old lady who swallowed a %s.\n%s\n" % [ critters.first.name, critters.first.aside, ] end
  126. attr_reader :critters def initialize(critters) @critters = critters end def incident

    "I know an old lady who swallowed a %s.\n%s\n" % [ critters.first.name, critters.first.aside, ] end
  127. attr_reader :critters, :critter def initialize(critters) @critters = critters @critter =

    critters.first end def incident "I know an old lady who swallowed a %s.\n%s\n" % [ critter.name, critter.aside, ] end
  128. def incident "I know an old lady who swallowed a

    %s.\n%s\n" % [ critter.name, critter.aside, ] end def recap case critters.length when 1, 8 "" else "%s\n" % chain + "%s\n" % "I don't know why she swallowed the fly. Perhaps she'll die." end end def motivation(predator, prey) "She swallowed the %s to catch the %s." % [ predator.name, prey.epithet, ] end
  129. def incident "I know an old lady who swallowed a

    %s.\n%s\n" % [ critter.name, critter.aside, ] end def recap case critters.length when 1, 8 "" else "%s\n" % chain + "%s\n" % "I don't know why she swallowed the fly. Perhaps she'll die." end end def motivation(predator, prey) "She swallowed the %s to catch the %s." % [ predator.name, prey.epithet, ] end
  130. def incident "I know an old lady who swallowed a

    %s.\n%s\n" % [ critter.name, critter.aside, ] end def recap case critters.length when 1, 8 "" else "%s\n" % chain + "%s\n" % "I don't know why she swallowed the fly. Perhaps she'll die." end end def motivation(predator, prey) "She swallowed the %s to catch the %s." % [ predator.name, prey.epithet, ] end
  131. def incident "I know an old lady who swallowed a

    %s.\n%s\n" % [ critter.name, critter.aside, ] end def recap case critters.length when 1, 8 "" else "%s\n" % chain + "%s\n" % critters.last.aside end end def motivation(predator, prey) "She swallowed the %s to catch the %s." % [ predator.name, prey.epithet, ] end
  132. class Verse attr_reader :critters, :critter def initialize(critters) @critters = critters

    @critter = critters.first end def to_s incident + recap end private def incident "I know an old lady who swallowed a %s.\n%s\n" % [ critter.name, critter.aside, ] end def recap case critters.length when 1, 8 "" else "%s\n" % chain + "%s\n" % critters.last.aside end end def chain critters.each_cons(2).map {|pair| motivation(*pair) }.join("\n") end def motivation(predator, prey) "She swallowed the %s to catch the %s." % [ predator.name, prey.epithet, ] end end attr_reader :critters, :critter def initialize(critters) @critters = critters @critter = critters.first end
  133. def to_s incident + recap end class Verse attr_reader :critters,

    :critter def initialize(critters) @critters = critters @critter = critters.first end def to_s incident + recap end private def incident "I know an old lady who swallowed a %s.\n%s\n" % [ critter.name, critter.aside, ] end def recap case critters.length when 1, 8 "" else "%s\n" % chain + "%s\n" % critters.last.aside end end def chain critters.each_cons(2).map {|pair| motivation(*pair) }.join("\n") end def motivation(predator, prey) "She swallowed the %s to catch the %s." % [ predator.name, prey.epithet, ] end end
  134. def incident "I know an old lady..." % [ critter.name,

    critter.aside, ] end class Verse attr_reader :critters, :critter def initialize(critters) @critters = critters @critter = critters.first end def to_s incident + recap end private def incident "I know an old lady who swallowed a %s.\n%s\n" % [ critter.name, critter.aside, ] end def recap case critters.length when 1, 8 "" else "%s\n" % chain + "%s\n" % critters.last.aside end end def chain critters.each_cons(2).map {|pair| motivation(*pair) }.join("\n") end def motivation(predator, prey) "She swallowed the %s to catch the %s." % [ predator.name, prey.epithet, ] end end
  135. class Verse attr_reader :critters, :critter def initialize(critters) @critters = critters

    @critter = critters.first end def to_s incident + recap end private def incident "I know an old lady who swallowed a %s.\n%s\n" % [ critter.name, critter.aside, ] end def recap case critters.length when 1, 8 "" else "%s\n" % chain + "%s\n" % critters.last.aside end end def chain critters.each_cons(2).map {|pair| motivation(*pair) }.join("\n") end def motivation(predator, prey) "She swallowed the %s to catch the %s." % [ predator.name, prey.epithet, ] end end def recap case critters.length when 1, 8 "" else "%s\n" % chain + "%s\n" % critters.last.aside end end
  136. def chain critters.each_cons(2).map {|pair| motivation(*pair) }.join("\n") end class Verse attr_reader

    :critters, :critter def initialize(critters) @critters = critters @critter = critters.first end def to_s incident + recap end private def incident "I know an old lady who swallowed a %s.\n%s\n" % [ critter.name, critter.aside, ] end def recap case critters.length when 1, 8 "" else "%s\n" % chain + "%s\n" % critters.last.aside end end def chain critters.each_cons(2).map {|pair| motivation(*pair) }.join("\n") end def motivation(predator, prey) "She swallowed the %s to catch the %s." % [ predator.name, prey.epithet, ] end end
  137. def motivation(predator, prey) "... %s to catch the %s." %

    [ predator.name, prey.epithet, ] end class Verse attr_reader :critters, :critter def initialize(critters) @critters = critters @critter = critters.first end def to_s incident + recap end private def incident "I know an old lady who swallowed a %s.\n%s\n" % [ critter.name, critter.aside, ] end def recap case critters.length when 1, 8 "" else "%s\n" % chain + "%s\n" % critters.last.aside end end def chain critters.each_cons(2).map {|pair| motivation(*pair) }.join("\n") end def motivation(predator, prey) "She swallowed the %s to catch the %s." % [ predator.name, prey.epithet, ] end end
  138. class Song DATA = [...] def initialize @critters = DATA.map

    {|row| Critter.new(*row)} end # ... end
  139. class Verse # ... def recap case critters.length when 1,

    8 "" else "%s\n" % chain + "%s\n" % critters.last.aside end end # ... end
  140. class Verse # ... def recap case critters.length when 1,

    8 "" else "%s\n" % chain + "%s\n" % critters.last.aside end end end
  141. # else class LongVerse # ... def recap "%s\n" %

    chain + "%s\n" % critters.last.aside end end # when 1, 8 class ShortVerse # ... def recap "" end end
  142. # else class LongVerse # ... def recap "%s\n" %

    chain + "%s\n" % critters.last.aside end end # when 1, 8 class ShortVerse # ... def recap "" end end
  143. # else class LongVerse # ... def recap "%s\n" %

    chain + "%s\n" % critters.last.aside end def chain # ... def motivation(predator, prey) # ... end # when 1, 8 class ShortVerse # ... def recap "" end end
  144. class LongVerse < ShortVerse private def recap "%s\n" % chain

    + "%s\n" % critters.last.aside end end
  145. class LongVerse < ShortVerse private def recap "%s\n" % chain

    + "%s\n" % critters.last.aside end def chain # ... def motivation(predator, prey) # ... end
  146. class Song def self.verse_builder(critters, i) case i when 1, critters.length

    ShortVerse else LongVerse end.new(critters.last(i)) end end
  147. class Verse def self.for(critters, i) case i when 1, critters.length

    ShortVerse else LongVerse end.new(critters.last(i)) end end
  148. data = [ ["D", nil, "Nope."], ["C", nil, "ZOMG C!"],

    ["B", "that blah blah", "Squee, B!"], ["A", nil, "IDK why A."], ]
  149. <<-SONG I know an old lady who swallowed an A.

    IDK why A. I know an old lady who swallowed a B. Squee, B! She swallowed the B to catch the A. IDK why A. I know an old lady who swallowed a C. ZOMG C! She swallowed the C to catch the B that blah blah. She swallowed the B to catch the A. IDK why A. I know an old lady who swallowed a D. Nope. SONG
  150. <<-SONG I know an old lady who swallowed an A.

    IDK why A. I know an old lady who swallowed a B. Squee, B! She swallowed the B to catch the A. IDK why A. I know an old lady who swallowed a C. ZOMG C! She swallowed the C to catch the B that blah blah. She swallowed the B to catch the A. IDK why A. I know an old lady who swallowed a D. Nope. SONG
  151. <<-SONG I know an old lady who swallowed an A.

    IDK why A. I know an old lady who swallowed a B. Squee, B! She swallowed the B to catch the A. IDK why A. I know an old lady who swallowed a C. ZOMG C! She swallowed the C to catch the B that blah blah. She swallowed the B to catch the A. IDK why A. I know an old lady who swallowed a D. Nope. SONG
  152. <<-SONG I know an old lady who swallowed an A.

    IDK why A. I know an old lady who swallowed a B. Squee, B! She swallowed the B to catch the A. IDK why A. I know an old lady who swallowed a C. ZOMG C! She swallowed the C to catch the B that blah blah. She swallowed the B to catch the A. IDK why A. I know an old lady who swallowed a D. Nope. SONG
  153. 1) Failure: SongTest#test_alt_critters [song_test.rb:90]: --- expected +++ actual @@ -1,4

    +1,4 @@ -"I know an old lady who swallowed an A. +"I know an old lady who swallowed a A.
  154. class Critter < Struct.new(:name, :qualifier, :aside) def epithet [name, qualifier].compact.join("

    ") end def article if name[0] =~ /[aeiouAEIOU]/ "an" else "a" end end end