Share
Embed
Succession
Refactoring sometimes devolves into an appalling mess. You're chasing a broken test suite, and every change just makes it worse. At other times it's a slow, controlled process culminating in dreadful design.
This talk presents an end-to-end refactoring that demonstrates simple strategies to avoid such misadventures.
Katrina Owen
May 06, 2016
Transcript
304 slides
-
I know an old lady who swallowed a . spider
She swallowed the spider to catch the fly. -
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. -
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. -
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. -
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. -
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. -
/ %@. @# @@@@( (@. ,@@@@@@@@, ,@% #@@@@@@@@@@@ .@& (@@@@@@@@@@@@@%
@@( *@@@@@@@@@@@@@@@ (@@/ ,@@@@@@@@@@@@@@@@@, @/ @@@, %@@@@@@@@@@@@@@@@@@/ &@( &@@@ @@@@@@@@@@@@@@@@@@@@# &@/ @@@@. @@@@@@@@@@@@@@@@@@@@@/ &@# ,@@@( /@@@@@@@@@@@@@@@@@@@@@, %@& (@@, @@@. #@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ &@@. @@/ /@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@&/ &@@% /@@, %@@@@@@@@@@@@@@@@@@@@@@@@@/ %@@@. %@@* .@@@@@@@@@@@@@@@@@@@@@@@@@@@ %@@@/ @@@, &@@@@@@@@@@@@@@@@@@@@@@@@@@@& ./(%##////#. ,@@@@@@,,,.,.,.... ,@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@& *&@@@@@@@@@@@@@@@@@#. @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@# .&@@@@@& @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@/ /@@@@@&@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@# /@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@# ,,. #@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@* %@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@&(*. (%%%&@&&@@@@ (@@@* /@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@* &@@@@@, . (@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@& ,@@@@* *@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@( *@@@& @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@/ #, &@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@. ,%@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@&, /@@#&@@@@@@@& ,#@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@% *@@@@@@@@@@@@@ @@@@ ,@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@( .(@@@@@@@@% .@@@& (@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ ,@@@% &@@@@/,(#@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@. (@@@ #@@@@# .*,(@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@/ (@@@ @@@@ .,(#%&&@@@@@@@@@@@@@@@@@, *@@@% .@@@, .,*(##(*, ,@@@@@@/ @@@(. .@@@@( /@@@@@@&%((/, *@@@@ .*#&@@@@@@/ .@@@& ,@@&, *@@( (@@@. (@& *&% /@# /@. *@. %* -
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 -
<<-SONG I know an old lady who swallowed a fly.
# ... She's dead, of course! SONG -
def lyrics <<-SONG I know an old lady who swallowed
a fly. # ... She's dead, of course! SONG end -
class Song def lyrics <<-SONG I know an old lady
who swallowed a fly. # ... She's dead, of course! SONG end end -
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 -
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 -
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 -
# ... 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. # ... -
# ... 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 -
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. -
<<-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 -
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 -
(1..8).map {|i| case i when 1 # ... when n
# ... end }.join("\n") -
def lyrics (1..8).map {|i| case i when 1 # ...
when n # ... end }.join("\n") end -
def song (1..8).map {|i| case i when 1 # ...
when n # ... end }.join("\n") end -
private def verse(i) case i when 1 # ... when
n # ... end end -
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 -
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 -
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 -
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 -
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 -
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 -
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 -
"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 -
"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 -
"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" % -
% "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... -
<<-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 -
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 -
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 -
case i when 1 "I know an old lady who
swallowed a %s.\n" % "%s\n" % -
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" % -
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" % -
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" % -
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" % -
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" % -
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" % -
case i when 8 "I know an old lady who
swallowed a %s.\n" % "%s\n" % -
"She swallowed the %s to catch the %s." % [
predator, prey, ] -
def swallow(predator, prey) "She swallowed the %s to catch the
%s." % [ predator, prey, ] end -
def to_catch(predator, prey) "She swallowed the %s to catch the
%s." % [ predator, prey, ] end -
"She swallowed the %s to catch the %s." % [
predator, prey, ] -
def recurring_line(predator, prey) "She swallowed the %s to catch the
%s." % [ predator, prey, ] end -
def incremental_sentence(predator, prey) "She swallowed the %s to catch the
%s." % [ predator, prey, ] end -
def middle_phrase(predator, prey) "She swallowed the %s to catch the
%s." % [ predator, prey, ] end -
"She swallowed the %s to catch the %s." % [
predator, prey, ] -
def reasoning(predator, prey) "She swallowed the %s to catch the
%s." % [ predator, prey, ] end -
def why(predator, prey) "She swallowed the %s to catch the
%s." % [ predator, prey, ] end -
def motivation(predator, prey) "She swallowed the %s to catch the
%s." % [ predator, prey, ] end -
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 -
"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" + -
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 -
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. -
if prey == "spider" "She swallowed [...] that wriggled [...]."
else "She swallowed [...]." end -
if prey == "spider" "She swallowed [...] that wriggled [...]."
else "She swallowed [...]." end -
if prey == "spider" "She swallowed [...] that wriggled [...]."
else "She swallowed [...]." end -
if prey == "spider" "She swallowed [...] that wriggled [...]."
else "She swallowed [...]." end -
class Song DATA = [ ["horse"], ["cow"], ["goat"], ["dog"], ["cat"],
["bird"], ["spider", "that wriggled ..."], ["fly"], ] end -
class Song DATA = [...] attr_reader :critters def initialize @critters
= DATA.map {|row| Critter.new(*row) } end end -
def motivation(predator, prey) "She swallowed the %s to catch the
%s." % [ predator.name, [ prey.name, prey.qualifier, ].compact.join(" "), ] end -
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 -
def motivation(predator, prey) "She swallowed the %s to catch the
%s." % [ predator.name, [ prey.name, prey.qualifier, ].compact.join(" "), ] end -
def motivation(predator, prey) "She swallowed the %s to catch the
%s." % [ predator, prey, ] end -
def motivation(predator, prey) "She swallowed the %s to catch the
%s." % [ predator.name, [ prey.name, prey.qualifier, ].compact.join(" "), ] end -
def motivation(predator, prey) "She swallowed the %s to catch the
%s." % [ predator.name, [ prey.name, prey.qualifier, ].compact.join(" "), ] end TMI -
class Critter < Struct.new(:name, :qualifier) def epithet [ name, qualifier
].compact.join(" ") end end -
"%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 -
"%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 -
"%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" + -
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 -
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 -
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 -
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 -
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 -
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 -
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 -
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 -
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 -
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 -
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 -
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 -
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 -
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 -
I know an old lady who swallowed a . fly
I don't know why she swallowed a fly. Perhaps she'll die. -
I know an old lady who swallowed a . spider
It wriggled and jiggled and tickled inside her. -
I know an old lady who swallowed a . bird
How absurd to swallow a bird! -
I know an old lady who swallowed a . cat
Imagine that, to swallow a cat! -
I know an old lady who swallowed a . dog
What a hog, to swallow a dog! -
I know an old lady who swallowed a . goat
Just opened her throat and swallowed a goat! -
I know an old lady who swallowed a . cow
I don't know how she swallowed a cow! -
I know an old lady who swallowed a . horse
She's dead, of course! -
class Song DATA = [ ["horse"], ["cow"], ["goat"], ["dog"], ["cat"],
["bird"], ["spider", "that wriggled ..."], ["fly"], ] end -
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 -
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 -
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 -
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 -
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 -
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 -
<<-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 -
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 -
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 -
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 -
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 -
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 -
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 -
class Song def initialize # ... def lyrics # ...
private def verse(i) # ... def chain(i) # ... def motivation(predator, prey) # ... end -
class Song def initialize # ... def lyrics # ...
private def verse(i) # ... def chain(i) # ... def motivation(predator, prey) # ... end -
class Song def initialize # ... def lyrics # ...
end class Verse def verse(i) # ... def chain(i) # ... def motivation(predator, prey) # ... end -
class Song def initialize # ... def lyrics # ...
private def verse(i) # ... def chain(i) # ... def motivation(predator, prey) # ... end class Verse # ... end -
class Verse def verse(i) # ... def chain(i) # ...
def motivation(predator, prey) # ... end -
class Verse def verse(i) # ... def chain(i) # ...
def motivation(predator, prey) # ... end -
class Verse def initialize(critters) # ... def verse(i) # ...
def chain(i) # ... def motivation(predator, prey) # ... end -
class Verse attr_reader :critters def initialize(critters) # ... def verse(i)
# ... def chain(i) # ... def motivation(predator, prey) # ... end -
class Verse attr_reader :critters def initialize(critters) # ... def verse(i)
# ... def chain(i) # ... def motivation(predator, prey) # ... end -
class Verse attr_reader :critters def initialize(critters) # ... def verse
# ... def chain # ... def motivation(predator, prey) # ... end -
class Verse attr_reader :critters, :i def initialize(critters) @critters = critters
@i = critters.length end # ... end -
class Verse attr_reader :critters, :i def initialize(critters) # ... def
to_s # ... def chain # ... def motivation(predator, prey) # ... end -
class Verse attr_reader :critters, i def initialize(critters) # ... def
to_s # ... def chain # ... def motivation(predator, prey) # ... end -
class Verse attr_reader :critters, i def initialize(critters) # ... def
to_s # ... private def chain # ... def motivation(predator, prey) # ... end -
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 -
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 -
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 -
class Song def initialize # ... def lyrics (1..8).map {|i|
Verse.new(critters.last(i)) }.join("\n") end end -
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 -
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 -
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 -
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 -
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 -
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 -
case i when 1, 8 "" else "%s\n" % chain
+ "%s\n" % "I don't know why she swallowed..." end -
def summary case i when 1, 8 "" else "%s\n"
% chain + "%s\n" % "I don't know why she swallowed..." end end -
def recap case i when 1, 8 "" else "%s\n"
% chain + "%s\n" % "I don't know why she swallowed..." end end -
"I know an old lady who swallowed a %s.\n%s\n" %
[ critters.last(i).first.name, critters.last(i).first.aside, ] -
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 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 -
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 -
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 -
attr_reader :critters, :i def initialize(critters) @critters = critters @i =
critters.length end def to_s case i when 1, 8 # ... else # ... end end -
attr_reader :critters, :i def initialize(critters) @critters = critters @i =
critters.length end def to_s case i when 1, 8 # ... else # ... end end -
attr_reader :critters def initialize(critters) @critters = critters end def to_s
case critters.length when 1, 8 # ... else # ... end end -
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 -
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 -
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 -
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 -
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 -
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 -
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 -
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 -
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 -
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 -
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 -
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 -
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 -
class Song DATA = [...] def initialize @critters = DATA.map
{|row| Critter.new(*row)} end # ... end -
class Song DATA = [...] def initialize(data=DATA) @critters = DATA.map
{|row| Critter.new(*row)} end # ... end -
class Song DATA = [...] def initialize(data=DATA) @critters = data.map
{|row| Critter.new(*row)} end # ... end -
class Verse # ... def recap case critters.length when 1,
8 "" else "%s\n" % chain + "%s\n" % critters.last.aside end end # ... end -
class Verse # ... def recap case critters.length when 1,
8 "" else "%s\n" % chain + "%s\n" % critters.last.aside end end end -
class LongVerse # ... def recap end end class ShortVerse
# ... def recap end end -
# else class LongVerse # ... def recap "%s\n" %
chain + "%s\n" % critters.last.aside end end # when 1, 8 class ShortVerse # ... def recap "" end end -
# else class LongVerse # ... def recap "%s\n" %
chain + "%s\n" % critters.last.aside end end # when 1, 8 class ShortVerse # ... def recap "" end end -
# 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 -
class {Short,Long}Verse attr_reader :critters def initialize(critters) # ... def to_s
# ... private def recap # ... end end -
class ShortVerse attr_reader :critters def initialize(critters) # ... def to_s
# ... private def recap "" end end -
class LongVerse < ShortVerse private def recap "%s\n" % chain
+ "%s\n" % critters.last.aside end end -
class LongVerse < ShortVerse private def recap "%s\n" % chain
+ "%s\n" % critters.last.aside end def chain # ... def motivation(predator, prey) # ... end -
class Song # ... def lyrics (1..critters.length).map {|i| ???.???(critters, i)
}.join("\n") end # ... end -
class Song def self.verse_builder(critters, i) case i when 1, critters.length
ShortVerse else LongVerse end.new(critters.last(i)) end end -
class Verse def self.for(critters, i) case i when 1, critters.length
ShortVerse else LongVerse end.new(critters.last(i)) end end -
class Song # ... def lyrics (1..critters.length).map {|i| Verse.for(critters, i)
}.join("\n") end # ... end -
data = [ ["D", nil, "Nope."], ["C", nil, "ZOMG C!"],
["B", "that blah blah", "Squee, B!"], ["A", nil, "IDK why A."], ] -
<<-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 -
<<-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 -
<<-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 -
<<-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 -
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. -
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