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.

51ee7bed9ecbc33aec92517f1fbb6cc2?s=128

Katrina Owen

May 06, 2016
Tweet

More Decks by Katrina Owen

Other Decks in Programming

Transcript

  1. TVDDFTTJPO A Refactoring Story in Ruby Katrina Owen @kytrinyx http://exercism.io

  2. I know an old lady who swallowed a . fly

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

    She swallowed the spider to catch the fly.
  4. 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.
  5. 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.
  6. 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.
  7. 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.
  8. 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.
  9. I know an old lady who swallowed a . horse

  10. EFBE PGDPVSTF 4IFT

  11. / %@. @# @@@@( (@. ,@@@@@@@@, ,@% #@@@@@@@@@@@ .@& (@@@@@@@@@@@@@%

    @@( *@@@@@@@@@@@@@@@ (@@/ ,@@@@@@@@@@@@@@@@@, @/ @@@, %@@@@@@@@@@@@@@@@@@/ &@( &@@@ @@@@@@@@@@@@@@@@@@@@# &@/ @@@@. @@@@@@@@@@@@@@@@@@@@@/ &@# ,@@@( /@@@@@@@@@@@@@@@@@@@@@, %@& (@@, @@@. #@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ &@@. @@/ /@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@&/ &@@% /@@, %@@@@@@@@@@@@@@@@@@@@@@@@@/ %@@@. %@@* .@@@@@@@@@@@@@@@@@@@@@@@@@@@ %@@@/ @@@, &@@@@@@@@@@@@@@@@@@@@@@@@@@@& ./(%##////#. ,@@@@@@,,,.,.,.... ,@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@& *&@@@@@@@@@@@@@@@@@#. @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@# .&@@@@@& @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@/ /@@@@@&@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@# /@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@# ,,. #@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@* %@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@&(*. (%%%&@&&@@@@ (@@@* /@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@* &@@@@@, . (@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@& ,@@@@* *@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@( *@@@& @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@/ #, &@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@. ,%@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@&, /@@#&@@@@@@@& ,#@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@% *@@@@@@@@@@@@@ @@@@ ,@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@( .(@@@@@@@@% .@@@& (@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ ,@@@% &@@@@/,(#@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@. (@@@ #@@@@# .*,(@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@/ (@@@ @@@@ .,(#%&&@@@@@@@@@@@@@@@@@, *@@@% .@@@, .,*(##(*, ,@@@@@@/ @@@(. .@@@@( /@@@@@@&%((/, *@@@@ .*#&@@@@@@/ .@@@& ,@@&, *@@( (@@@. (@& *&% /@# /@. *@. %*
  12. 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
  13. <<-SONG I know an old lady who swallowed a fly.

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

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

    who swallowed a fly. # ... She's dead, of course! SONG end end
  16. JOUIF CFHJOOJOH

  17. OPQF

  18. BOETPJU CFHJOT

  19. OPQF

  20. 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
  21. 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
  22. PODFVQPOB UJNF

  23. OPQF

  24. SFGBDUPS

  25. 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
  26. EVQMJDBUJPO

  27. # ... 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. # ...
  28. # ... 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
  29. 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.
  30. <<-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
  31. JOEJSFDUJPO

  32. 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
  33. (1..8).map {|i| case i when 1 # ... when n

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

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

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

  37. private def verse(i) case i when 1 # ... when

    n # ... end end
  38. 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
  39. 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
  40. 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
  41. 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
  42. UFNQMBUFEBUB

  43. "template vs data"

  44. "template vs %s" % "data"

  45. "template vs %s" % "data"

  46. "template vs %s" % "data"

  47. "template vs %s" % "data"

  48. "%s vs template" % "data"

  49. "template vs %s" % "data"

  50. "template vs %s" % "data"

  51. 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
  52. 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
  53. 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
  54. "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
  55. "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
  56. "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" %
  57. % "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...
  58. <<-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
  59. 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
  60. 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
  61. None
  62. BMHPSJUIN

  63. case i when 1 "I know an old lady who

    swallowed a %s.\n" % "%s\n" %
  64. 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" %
  65. 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" %
  66. 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" %
  67. 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" %
  68. 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" %
  69. 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" %
  70. case i when 8 "I know an old lady who

    swallowed a %s.\n" % "%s\n" %
  71. "She swallowed the %s to catch the %s"

  72. "She swallowed the %s to catch the %s" * n

  73. "She swallowed the %s to catch the %s" % [predator,

    prey]
  74. "She swallowed the %s to catch the %s." % [

    predator, prey, ]
  75. def swallow(predator, prey) "She swallowed the %s to catch the

    %s." % [ predator, prey, ] end
  76. def to_catch(predator, prey) "She swallowed the %s to catch the

    %s." % [ predator, prey, ] end
  77. def blue "FF0000" end

  78. "She swallowed the %s to catch the %s." % [

    predator, prey, ]
  79. def recurring_line(predator, prey) "She swallowed the %s to catch the

    %s." % [ predator, prey, ] end
  80. def incremental_sentence(predator, prey) "She swallowed the %s to catch the

    %s." % [ predator, prey, ] end
  81. def middle_phrase(predator, prey) "She swallowed the %s to catch the

    %s." % [ predator, prey, ] end
  82. "She swallowed the %s to catch the %s." % [

    predator, prey, ]
  83. def reasoning(predator, prey) "She swallowed the %s to catch the

    %s." % [ predator, prey, ] end
  84. def why(predator, prey) "She swallowed the %s to catch the

    %s." % [ predator, prey, ] end
  85. def motivation(predator, prey) "She swallowed the %s to catch the

    %s." % [ predator, prey, ] end
  86. ["cow", "goat"] ["goat", "dog"] ["dog", "cat"] ["cat", "bird"] ["bird", "spider"]

    ["spider", "fly"]
  87. ["cow", "goat"] ["goat", "dog"] ["dog", "cat"] ["cat", "bird"] ["bird", "spider"]

    ["spider", "fly"]
  88. ["cow", "goat"] ["goat", "dog"] ["dog", "cat"] ["cat", "bird"] ["bird", "spider"]

    ["spider", "fly"]
  89. ["cow", "goat"] ["goat", "dog"] ["dog", "cat"] ["cat", "bird"] ["bird", "spider"]

    ["spider", "fly"]
  90. ["cow", "goat"] ["goat", "dog"] ["dog", "cat"] ["cat", "bird"] ["bird", "spider"]

    ["spider", "fly"]
  91. ["cow", "goat"] ["goat", "dog"] ["dog", "cat"] ["cat", "bird"] ["bird", "spider"]

    ["spider", "fly"]
  92. ["cow", "goat", "dog", ...]

  93. [...].each_cons(2)

  94. ["cow", "goat", "dog", "cat", "bird", ...]

  95. critters.each_cons(2).map {|pair| motivation(*pair) }

  96. critters.each_cons(2).map {|pair| motivation(*pair) }

  97. critters.each_cons(2).map {|pair| motivation(*pair) }.join("\n")

  98. def sequence(critters) critters.each_cons(2).map {|pair| motivation(*pair) }.join("\n") end

  99. def chain(critters) critters.each_cons(2).map {|pair| motivation(*pair) }.join("\n") end

  100. food chain BIJFSBSDIJDBMTFSJFTPG PSHBOJTNTFBDIEFQFOEFOU POUIFOFYUBTBTPVSDFPG GPPE

  101. def chain(critters) critters.each_cons(2).map {|pair| motivation(*pair) }.join("\n") end def motivation(predator, prey)

    "She swallowed the %s to catch the %s." % [ predator, prey, ] end
  102. "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" +
  103. def chain(critters) critters.each_cons(2).map {|pair| motivation(*pair) }.join("\n") end def motivation(predator, prey)

    "She swallowed the %s to catch the %s." % [ predator, prey, ] end
  104. None
  105. BOPNBMZ

  106. 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.
  107. if prey == "spider" # ... else # ... end

  108. EJGGFSFODF

  109. if prey == "spider" "She swallowed [...] that wriggled [...]."

    else "She swallowed [...]." end
  110. if prey == "spider" "She swallowed [...] that wriggled [...]."

    else "She swallowed [...]." end
  111. if prey == "spider" "She swallowed [...] that wriggled [...]."

    else "She swallowed [...]." end
  112. if prey == "spider" "She swallowed [...] that wriggled [...]."

    else "She swallowed [...]." end
  113. if prey == "spider" " that wriggled [...]" else ???

    end
  114. if prey == "spider" " that wriggled [...]" end

  115. TZNNFUSZ

  116. if prey == "spider" " that wriggled..." else "" end

  117. def distinctive_features if prey == "spider" " that wriggled..." else

    "" end end
  118. def qualifier if prey == "spider" " that wriggled..." else

    "" end end
  119. if prey == "spider" " that wriggled..." end

  120. def spider_tag if prey == "spider" " that wriggled..." end

    end
  121. def qualifier if prey == "spider" " that wriggled..." else

    "" end end
  122. def qualifier(prey) if prey == "spider" " that wriggled..." else

    "" end end
  123. def qualifier(critter) if critter == "spider" " that wriggled..." else

    "" end end
  124. qualifier(critter)

  125. critter.qualifier

  126. class Critter < Struct.new(:name, :qualifier) end

  127. class Song DATA = [ ] end

  128. class Song DATA = [ ["horse"], ["cow"], ["goat"], ["dog"], ["cat"],

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

    = DATA.map {|row| Critter.new(*row) } end end
  130. def motivation(predator, prey) # ... end

  131. def motivation(predator, prey) "She swallowed the %s to catch the

    %s." % [ predator.name, [ prey.name, prey.qualifier, ].compact.join(" "), ] end
  132. 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
  133. def motivation(predator, prey) "She swallowed the %s to catch the

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

    %s." % [ predator, prey, ] end
  135. def motivation(predator, prey) "She swallowed the %s to catch the

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

    %s." % [ predator.name, [ prey.name, prey.qualifier, ].compact.join(" "), ] end TMI
  137. [ critter.name, critter.qualifier ].compact.join(" ")

  138. def epithet(critter) [ critter.name, critter.qualifier ].compact.join(" ") end

  139. def epithet(critter) [ critter.name, critter.qualifier ].compact.join(" ") end

  140. class Critter < Struct.new(:name, :qualifier) def epithet [ name, qualifier

    ].compact.join(" ") end end
  141. None
  142. "%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
  143. "%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
  144. "%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" +
  145. # Running: . 1 assertions, 0 failures, 0 errors, 0

    skips
  146. 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
  147. 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
  148. 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
  149. TJNJMBSJUZ

  150. 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
  151. 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
  152. 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
  153. 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
  154. 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
  155. 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
  156. 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
  157. critters.last(i).first

  158. critters.last(i).first.name

  159. 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
  160. 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
  161. 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
  162. 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
  163. I know an old lady who swallowed a . fly

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

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

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

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

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

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

    I don't know how she swallowed a cow!
  170. I know an old lady who swallowed a . horse

    She's dead, of course!
  171. critter.aside

  172. class Song DATA = [ ["horse"], ["cow"], ["goat"], ["dog"], ["cat"],

    ["bird"], ["spider", "that wriggled ..."], ["fly"], ] end
  173. 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
  174. 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
  175. 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
  176. 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
  177. 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
  178. 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
  179. None
  180. <<-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
  181. 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
  182. 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
  183. 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
  184. class Critter < Struct.new(:name, :qualifier, :aside) def epithet [name, qualifier].compact.join("

    ") end end
  185. 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
  186. 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
  187. 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
  188. DPIFTJPO

  189. class Song def initialize # ... def lyrics # ...

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

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

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

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

    def motivation(predator, prey) # ... end
  194. critters.last(i)

  195. class Verse def verse(i) # ... def chain(i) # ...

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

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

    # ... def chain(i) # ... def motivation(predator, prey) # ... end
  198. Verse.new(critters)

  199. Verse.new(critters.last(i))

  200. class Verse attr_reader :critters def initialize(critters) # ... def verse(i)

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

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

    @i = critters.length end # ... end
  203. Verse.new(critters.last(i)).verse

  204. Verse.new(critters.last(i)).to_s

  205. class Verse attr_reader :critters, :i def initialize(critters) # ... def

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

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

    to_s # ... private def chain # ... def motivation(predator, prey) # ... end
  208. 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
  209. 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
  210. 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
  211. class Song def initialize # ... def lyrics (1..8).map {|i|

    Verse.new(critters.last(i)) }.join("\n") end end
  212. # Running: . 1 assertions, 0 failures, 0 errors, 0

    skips
  213. 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
  214. class Critter < Struct.new(:name, :qualifier, :aside) def epithet [name, qualifier].compact.join("

    ") end end
  215. 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
  216. 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
  217. None
  218. SFTJEVF

  219. 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
  220. 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
  221. 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
  222. case i when 1, 8 "" else "%s\n" % chain

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

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

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

    [ critters.last(i).first.name, critters.last(i).first.aside, ]
  226. 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
  227. def to_s incident + recap end

  228. 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
  229. 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
  230. 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
  231. attr_reader :critters, :i def initialize(critters) @critters = critters @i =

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

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

    case critters.length when 1, 8 # ... else # ... end end
  234. 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
  235. 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
  236. 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
  237. 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
  238. 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
  239. 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
  240. 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
  241. 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
  242. 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
  243. 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
  244. 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
  245. 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
  246. 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
  247. None
  248. QPMZNPSQIJTN

  249. OPQF

  250. DIBOHF

  251. None
  252. None
  253. None
  254. class Song DATA = [...] # ... end

  255. class Song DATA = [...] def initialize @critters = DATA.map

    {|row| Critter.new(*row)} end # ... end
  256. class Song DATA = [...] def initialize(data=DATA) @critters = DATA.map

    {|row| Critter.new(*row)} end # ... end
  257. class Song DATA = [...] def initialize(data=DATA) @critters = data.map

    {|row| Critter.new(*row)} end # ... end
  258. def lyrics (1..8).map {|i| Verse.new(critters.last(i)) }.join("\n") end

  259. def lyrics (1..8).map {|i| Verse.new(critters.last(i)) }.join("\n") end

  260. def lyrics (1..critters.length).map {|i| Verse.new(critters.last(i)) }.join("\n") end

  261. class Verse # ... def recap case critters.length when 1,

    8 "" else "%s\n" % chain + "%s\n" % critters.last.aside end end # ... end
  262. PQUJPOT

  263. Verse.new(critters.last(i))

  264. Verse.new(critters.last(i)) Verse.new(critters.last(i), critters.length)

  265. Verse.new(critters.last(i)) Verse.new(critters.last(i), critters.length) Verse.new(critters, i)

  266. Verse.new(critters.last(i)) Verse.new(critters.last(i), critters.length) Verse.new(critters, i) Verse.new(critters.last(i), :short)

  267. PQUJPOT

  268. QPMZNPSQIJTN

  269. class Verse # ... def recap case critters.length when 1,

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

    # ... def recap end end
  271. # else class LongVerse # ... def recap "%s\n" %

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

    chain + "%s\n" % critters.last.aside end end # when 1, 8 class ShortVerse # ... def recap "" end end
  273. # 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
  274. class {Short,Long}Verse attr_reader :critters def initialize(critters) # ... def to_s

    # ... private def recap # ... end end
  275. class ShortVerse attr_reader :critters def initialize(critters) # ... def to_s

    # ... private def recap "" end end
  276. class LongVerse < ShortVerse end

  277. class LongVerse < ShortVerse private def recap "%s\n" % chain

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

    + "%s\n" % critters.last.aside end def chain # ... def motivation(predator, prey) # ... end
  279. class Song # ... def lyrics (1..critters.length).map {|i| ???.???(critters, i)

    }.join("\n") end # ... end
  280. case i when 1, critters.length ShortVerse else LongVerse end

  281. case i when 1, critters.length ShortVerse else LongVerse end.new(critters.last(i))

  282. class Song def self.verse_builder(critters, i) case i when 1, critters.length

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

    ShortVerse else LongVerse end.new(critters.last(i)) end end
  284. class Song # ... def lyrics (1..critters.length).map {|i| Verse.for(critters, i)

    }.join("\n") end # ... end
  285. qFYJCJMJUZ

  286. data = [ ["D", nil, "Nope."], ["C", nil, "ZOMG C!"],

    ["B", "that blah blah", "Squee, B!"], ["A", nil, "IDK why A."], ]
  287. <<-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
  288. <<-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
  289. <<-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
  290. <<-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
  291. assert_equal expected, Song.new(data).lyrics

  292. 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.
  293. [FCSB B

  294. BMMJHBUPS BO

  295. 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
  296. # Running: .. 2 assertions, 0 failures, 0 errors, 0

    skips
  297. UIFONBLFUIFFBTZDIBOHF - Kent Beck NBLFUIFDIBOHFFBTZ XBSOJOHUIJTNBZCFIBSE

  298. SFGBDUPSJOH is insight

  299. UIBOLZPV

  300. HJUIVCDPNLZUSJOZY succession

  301. Katrina Owen Sandi Metz & by CPUUMFTCPPLDPN

  302. FYFSDJTN JP IUUQ

  303. Katrina Owen FYFSDJTNJP !LZUSJOZY

  304. UIBOLT <3