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

Katrina Owen_One small-step_Codemotion Berlin 2019

Codemotion
November 12, 2019

Katrina Owen_One small-step_Codemotion Berlin 2019

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.

About:
Katrina Owen, Senior Software Engineer - GitHub

Katrina is an engineer at GitHub. She accidentally became a developer while pursuing a degree in molecular biology. When programming, her focus is on automation, workflow optimization, and refactoring. She works primarily in Go and Ruby, contributes to several open source projects, and is the creator of exercism.io, a platform for code practice and programming mentorship.

Codemotion

November 12, 2019
Tweet

More Decks by Codemotion

Other Decks in Programming

Transcript

  1. She swallowed the spider to catch the fly. I know

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

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

    the bird to catch the spider. She swallowed the spider to catch the fly. I know an old lady who swallowed a cat.
  4. 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. I know an old lady who swallowed a dog.
  5. 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. I know an old lady who swallowed a goat.
  6. 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. I know an old lady who swallowed a cow.
  7. I know an old lady who swall Imagine that, to

    swallow a c She swallowed the cat to cat She swallowed the bird to ca She swallowed the spider to I don't know why she swallow
  8. 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!
  9. I know an old lady who swallowed a fly. #

    ... She's dead, of course!
  10. <<~SONG I know an old lady who swallowed a fly.

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

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

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

    who swallowed a fly. # ... She's dead of course. SONG end end
  14. <<~SONG I know an old lady who swallowed a fly.

    # ... She's dead of course. SONG
  15. expected = <<~SONG I know an old lady who swallowed

    a fly. # ... She's dead of course. SONG
  16. expected = <<~SONG I know an old lady who swallowed

    a fly. # ... She's dead of course. SONG assert_equal expected, Song.new.lyrics
  17. <<~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
  18. 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... She swallowed the spider to catch the fly. I don't know why she swallowed the fly...
  19. 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...
  20. 1. How to construct a verse. 2. How to string

    verses together. 3. Support for arbitrary creatures.
  21. 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
  22. case i when 1 "I know an old lady who

    swallowed a %s.\n" % "fly" + "%s\n" % "I don't when 2 "I know an old lady who swallowed a %s.\n" % "spider" "%s\n" % "It wrigg "She swallowed the %s to catch the %s.\n" % ["spider" "%s\n" % "I don't when 3 "I know an old lady who swallowed a %s.\n" % "bird" + "%s\n" % "How absu "She swallowed the %s to catch the %s.\n" % ["bird", "She swallowed the %s to catch the %s.\n" % ["spider" "%s\n" % "I don't
  23. "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" %
  24. % "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..."
  25. <<~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
  26. 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
  27. 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
  28. case i when 1 "I know an old lady who

    swallowed a %s.\n" % "%s\n" %
  29. 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" %
  30. 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" %
  31. 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" %
  32. 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" %
  33. 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" %
  34. 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" %
  35. case i when 8 "I know an old lady who

    swallowed a %s.\n" % "%s\n" %
  36. "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" +
  37. "She swallowed the spider to catch the fly.\n" + "She

    swallowed the bird to catch the spider...\n" +
  38. She swallowed the bird to catch the spider that wriggled

    and jiggled and tickled inside her. She swallowed the spider to catch the fly.
  39. 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.
  40. DATA = [ ["horse", "", "She's dead, of course!"], ["cow",

    "", "I don't know how..."], ["goat", "", "Just opened her throat..."], ["dog", "", "What a hog, to swallow a dog!"], ["cat", "", "Imagine that, to swallow a cat!"], ["bird", "", "How absurd to swallow a bird!"], ["spider", "that wriggled...", "It wriggled..."], ["fly", "", "I don't know why..."], ]
  41. DATA = [ ["horse", "", "She's dead, of course!"], ["cow",

    "", "I don't know how..."], ["goat", "", "Just opened her throat..."], ["dog", "", "What a hog, to swallow a dog!"], ["cat", "", "Imagine that, to swallow a cat!"], ["bird", "", "How absurd to swallow a bird!"], ["spider", "that wriggled...", "It wriggled..."], ["fly", "", "I don't know why..."], ]
  42. DATA = [ ["horse", "", "She's dead, of course!"], ["cow",

    "", "I don't know how..."], ["goat", "", "Just opened her throat..."], ["dog", "", "What a hog, to swallow a dog!"], ["cat", "", "Imagine that, to swallow a cat!"], ["bird", "", "How absurd to swallow a bird!"], ["spider", "that wriggled...", "It wriggled..."], ["fly", "", "I don't know why..."], ]
  43. when 7 "I know an old lady who swallowed a

    %s.\n" % "cow" + "%s\n" % "I don't know how she swallowed..." + "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..."] + "She swallowed the %s to catch the %s.\n" % ["spider", "fly"] + "%s\n" % "I don't know why she swallowed..."
  44. when 7 "I know an old lady who swallowed a

    %s.\n" % critters.last(7).first.name + "%s\n" % "I don't know how she swallowed..." + "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..."] + "She swallowed the %s to catch the %s.\n" % ["spider", "fly"] + "%s\n" % "I don't know why she swallowed..."
  45. when 7 "I know an old lady who swallowed a

    %s.\n" % critters.last(7).first.name + "%s\n" % critters.last(7).first.aside + "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..."] + "She swallowed the %s to catch the %s.\n" % ["spider", "fly"] + "%s\n" % "I don't know why she swallowed..."
  46. when 7 "I know an old lady who swallowed a

    %s.\n" % critters.last(7).first.name + "%s\n" % critters.last(7).first.aside + "She swallowed the %s to catch the %s.\n" % chain(7) + "%s\n" % "I don't know why she swallowed..."
  47. when 7 "I know an old lady who swallowed a

    %s.\n" % critters.last(7).first.name + "%s\n" % critters.last(7).first.aside + "She swallowed the %s to catch the %s.\n" % chain(7) + "%s\n" % critters.last.aside
  48. 1. How to construct a verse. 2. How to string

    verses together. 3. Support for arbitrary creatures.
  49. 1. How to construct a verse. 2. How to string

    verses together. 3. Support for arbitrary creatures.
  50. 1. How to construct a verse. 2. How to string

    verses together. 3. Support for arbitrary creatures.
  51. 1. How to construct a verse. 2. How to string

    verses together. 3. Support for arbitrary creatures. A. Hard-coded DATA constant.
  52. 1. How to construct a verse. 2. How to string

    verses together. 3. Support for arbitrary creatures. A. Hard-coded DATA constant. B. Assumptions about creature count.
  53. def critters @critters ||= DATA.map {|row| Critter.new(*row) } end attr_reader

    :data def initialize(data = DATA) @data = data end
  54. def critters @critters ||= data.map {|row| Critter.new(*row) } end attr_reader

    :data def initialize(data = DATA) @data = data end
  55. 1. How to construct a verse. 2. How to string

    verses together. 3. Support for arbitrary creatures. A. Hard-coded DATA constant. B. Assumptions about creature count.
  56. 1. How to construct a verse. 2. How to string

    verses together. 3. Support for arbitrary creatures. A. Hard-coded DATA constant. B. Assumptions about creature count.
  57. case i when 1 # ... when 2 # ...

    when 3 # ... when 4 # ... when 5 # ... when 6 # ... when 7 # ... when 8 # ... end
  58. # ... when 2 "I know an old lady who

    swallowed a %s.\n" % critters.last(3).first.name + "%s\n" % critters.last(3).first.aside + "%s\n" % chain(3) + "%s\n" % critters.last.aside when 3 "I know an old lady who swallowed a %s.\n" % critters.last(4).first.name + "%s\n" % critters.last(4).first.aside + "%s\n" % chain(4) + "%s\n" % critters.last.aside when 4 # ...
  59. # ... when 2 "I know an old lady who

    swallowed a %s.\n" % critters.last(3).first.name + "%s\n" % critters.last(3).first.aside + "%s\n" % chain(3) + "%s\n" % critters.last.aside when 3 "I know an old lady who swallowed a %s.\n" % critters.last(4).first.name + "%s\n" % critters.last(4).first.aside + "%s\n" % chain(4) + "%s\n" % critters.last.aside when 4 # ...
  60. # ... 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" % critters.last.aside 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" % critters.last.aside when 4 # ...
  61. case i when 1 # ... when 2..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" % critters.last.aside when 8 # ... end
  62. 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..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" % critters.last.aside 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
  63. 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 when 2..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" % critters.last.aside end
  64. 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 when 2..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" % critters.last.aside end
  65. case i when 1, critters.count "I know an old lady

    who swallowed a %s.\n" % critters.last(i).first.name + "%s\n" % critters.last(i).first.aside when 2..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" % critters.last.aside end
  66. case i when 1, critters.count "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" % critters.last.aside end
  67. 1. How to construct a verse. 2. How to string

    verses together. 3. Support for arbitrary creatures. A. Hard-coded DATA constant. B. Assumptions about creature count.
  68. data = [ ["D", "", "Nope."], ["C", "", "ZOMG C!"],

    ["B", "that bla bla", "Squee, B!"], ["A", "", "IDK why A."], ]
  69. data = <<~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 bla bla. She swallowed the B to catch the A. IDK why A. I know an old lady who swallowed a D. Nope. SONG
  70. data = <<~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 bla bla. She swallowed the B to catch the A. IDK why A. I know an old lady who swallowed a D. Nope. SONG
  71. data = <<~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 bla bla. She swallowed the B to catch the A. IDK why A. I know an old lady who swallowed a D. Nope. SONG
  72. data = <<~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 bla bla. She swallowed the B to catch the A. IDK why A. I know an old lady who swallowed a D. Nope. SONG
  73. data = <<~SONG I know an old lady who swallowed

    an A. # ... Nope. SONG assert_equal expected, Song.new(data).lyrics
  74. data = [ ["D", "", "Nope."], ["C", "", "ZOMG C!"],

    ["B", "that bla bla", "Squee, B!"], ["A", "", "IDK why A."], ]
  75. data = [ ["a", "D", "", "Nope."], ["a", "C", "",

    "ZOMG C!"], ["a", "B", "that bla bla", "Squee, B!"], ["an", "A", "", "IDK why A."], ]