Slide 1

Slide 1 text

Katrina Owen @kytrinyx http://exercism.io Overkill

Slide 2

Slide 2 text

No content

Slide 3

Slide 3 text

1 2 ... 3563 3564 class Thing #... end /app/models/thing.rb

Slide 4

Slide 4 text

Slide 5

Slide 5 text

Oh. Shit.

Slide 6

Slide 6 text

1 2 ... 3563 3564 class Thing #... end /app/models/thing.rb

Slide 7

Slide 7 text

1 2 ... 3532 3533 class Thing #... end /app/models/thing.rb

Slide 8

Slide 8 text

something different

Slide 9

Slide 9 text

README

Slide 10

Slide 10 text

README Bob is a lackadaisical teenager. In conversation, his responses are very limited.

Slide 11

Slide 11 text

README

Slide 12

Slide 12 text

README Bob answers 'Sure.' if you ask him a question. He answers 'Whoa, chill out!' if you yell at him. He says 'Fine. Be that way!' if you address him without actually saying anything. He answers 'Whatever.' to anything else.

Slide 13

Slide 13 text

test suite

Slide 14

Slide 14 text

test suite

Slide 15

Slide 15 text

test suite "Does this cryogenic chamber make me look fat?" Sure.

Slide 16

Slide 16 text

test suite

Slide 17

Slide 17 text

test suite "WATCH OUT!" Whoa, chill out!

Slide 18

Slide 18 text

test suite

Slide 19

Slide 19 text

test suite "" Fine. Be that way!

Slide 20

Slide 20 text

test suite

Slide 21

Slide 21 text

test suite "Tom-ay-to, tom-aaaah-to." Whatever.

Slide 22

Slide 22 text

edge cases test suite

Slide 23

Slide 23 text

test suite

Slide 24

Slide 24 text

test suite "Ending with ? means a question." Whatever.

Slide 25

Slide 25 text

test suite

Slide 26

Slide 26 text

test suite "I HATE YOU" Whoa, chill out!

Slide 27

Slide 27 text

test suite

Slide 28

Slide 28 text

test suite "Let's go make out behind the gym!" Whatever.

Slide 29

Slide 29 text

test suite

Slide 30

Slide 30 text

test suite "WHAT THE HELL WERE YOU THINKING?" Whoa, chill out!

Slide 31

Slide 31 text

test suite

Slide 32

Slide 32 text

test suite "1, 2, 3" Whatever.

Slide 33

Slide 33 text

test suite

Slide 34

Slide 34 text

test suite "1, 2, 3 GO!" Whoa, chill out!

Slide 35

Slide 35 text

test suite

Slide 36

Slide 36 text

test suite "4?" Sure.

Slide 37

Slide 37 text

test suite

Slide 38

Slide 38 text

test suite "ZOMG THE %^*@#$(*^ ZOMBIES ARE COMING!!11!!1!" Whoa, chill out!

Slide 39

Slide 39 text

code

Slide 40

Slide 40 text

code 24 iterations

Slide 41

Slide 41 text

class Bob def hey (input ) if input=="Tom-ay-to, tom-aaaah-to." return"Whatever." elsif input == "WATCH OUT!" return "Whoa, chill out!" elsif input == "Does this cryogenic chamber make me look fat?" return "Sure." elsif input== "You are, what, like 15?" return "Sure." elsif input == "Let's go make out behind the gym!" return "Whatever." elsif input == "It's OK if you don't want to go to the DMV." return "Whatever." Iteration #1

Slide 42

Slide 42 text

return"Whoa, chill out!" elsif input == "Ending with ? means a question." return "Whatever." elsif input== "Wait! Hang on. Are you going to be OK?" return "Sure." elsif input=="" return"Fine. Be that way!" elsif input == " " return "Fine. Be that way!" elsif input == " " return "Fine. Be that way!" elsif input==" " return "Fine. Be that way!" elsif input == "Does this cryogenic chamber make me look fat?\nno return"Whatever." end end end Iteration #1

Slide 43

Slide 43 text

class Bob def hey (input ) if input=="Tom-ay-to, tom-aaaah-to." return"Whatever." elsif input == "WATCH OUT!" return "Whoa, chill out!" elsif input == "Does this cryogenic chamber make me look fat?" return "Sure." elsif input== "You are, what, like 15?" return "Sure." elsif input == "Let's go make out behind the gym!" return "Whatever." elsif input == "It's OK if you don't want to go to the DMV." return "Whatever." elsif input == "WHAT THE HELL WERE YOU THINKING?" return "Whoa, chill out!" elsif input == "1, 2, 3 GO!" return "Whoa, chill out!" elsif input =="1, 2, 3" return "Whatever." elsif input=="4?" return "Sure." elsif input == "ZOMG THE %^*@#$(*^ ZOMBIES ARE COMING!!11!!1!" return "Whoa, chill out!" elsif input == "I HATE YOU" return"Whoa, chill out!" elsif input == "Ending with ? means a question." return "Whatever." elsif input== "Wait! Hang on. Are you going to be OK?" return "Sure." elsif input=="" return"Fine. Be that way!" elsif input == " " return "Fine. Be that way!" elsif input == " " return "Fine. Be that way!" elsif input==" " return "Fine. Be that way!" elsif input == "Does this cryogenic chamber make me look fat?\nno" return"Whatever." end end end Iteration #1

Slide 44

Slide 44 text

class Bob def hey (input ) if input=="Tom-ay-to, tom-aaaah-to." return"Whatever." elsif input == "WATCH OUT!" return "Whoa, chill out!" elsif input == "Does this cryogenic chamber make me look fat?" return "Sure." elsif input== "You are, what, like 15?" return "Sure." elsif input == "Let's go make out behind the gym!" return "Whatever." elsif input == "It's OK if you don't want to go to the DMV." return "Whatever." elsif input == "WHAT THE HELL WERE YOU THINKING?" return "Whoa, chill out!" elsif input == "1, 2, 3 GO!" return "Whoa, chill out!" elsif input =="1, 2, 3" return "Whatever." elsif input=="4?" return "Sure." elsif input == "ZOMG THE %^*@#$(*^ ZOMBIES ARE COMING!!11!!1!" return "Whoa, chill out!" elsif input == "I HATE YOU" return"Whoa, chill out!" elsif input == "Ending with ? means a question." return "Whatever." elsif input== "Wait! Hang on. Are you going to be OK?" return "Sure." elsif input=="" return"Fine. Be that way!" elsif input == " " return "Fine. Be that way!" elsif input == " " return "Fine. Be that way!" elsif input==" " return "Fine. Be that way!" elsif input == "Does this cryogenic chamber make me look fat?\nno" return"Whatever." end end end Iteration #1

Slide 45

Slide 45 text

class Bob def hey (input ) if input=="Tom-ay-to, tom-aaaah-to." return"Whatever." elsif input == "WATCH OUT!" return "Whoa, chill out!" elsif input == "Does this cryogenic chamber make me look fat?" return "Sure." elsif input== "You are, what, like 15?" return "Sure." elsif input == "Let's go make out behind the gym!" return "Whatever." elsif input == "It's OK if you don't want to go to the DMV." return "Whatever." elsif input == "WHAT THE HELL WERE YOU THINKING?" return "Whoa, chill out!" elsif input == "1, 2, 3 GO!" return "Whoa, chill out!" elsif input =="1, 2, 3" return "Whatever." elsif input=="4?" return "Sure." elsif input == "ZOMG THE %^*@#$(*^ ZOMBIES ARE COMING!!11!!1!" return "Whoa, chill out!" elsif input == "I HATE YOU" return"Whoa, chill out!" elsif input == "Ending with ? means a question." return "Whatever." elsif input== "Wait! Hang on. Are you going to be OK?" return "Sure." elsif input=="" return"Fine. Be that way!" elsif input == " " return "Fine. Be that way!" elsif input == " " return "Fine. Be that way!" elsif input==" " return "Fine. Be that way!" elsif input == "Does this cryogenic chamber make me look fat?\nno" return"Whatever." end end end Iteration #1

Slide 46

Slide 46 text

class Bob def hey (input ) if input=="Tom-ay-to, tom-aaaah-to." return"Whatever." elsif input == "WATCH OUT!" return "Whoa, chill out!" elsif input == "Does this cryogenic chamber make me look fat?" return "Sure." elsif input== "You are, what, like 15?" return "Sure." elsif input == "Let's go make out behind the gym!" return "Whatever." elsif input == "It's OK if you don't want to go to the DMV." return "Whatever." elsif input == "WHAT THE HELL WERE YOU THINKING?" return "Whoa, chill out!" elsif input == "1, 2, 3 GO!" return "Whoa, chill out!" elsif input =="1, 2, 3" return "Whatever." elsif input=="4?" return "Sure." elsif input == "ZOMG THE %^*@#$(*^ ZOMBIES ARE COMING!!11!!1!" return "Whoa, chill out!" elsif input == "I HATE YOU" return"Whoa, chill out!" elsif input == "Ending with ? means a question." return "Whatever." elsif input== "Wait! Hang on. Are you going to be OK?" return "Sure." elsif input=="" return"Fine. Be that way!" elsif input == " " return "Fine. Be that way!" elsif input == " " return "Fine. Be that way!" elsif input==" " return "Fine. Be that way!" elsif input == "Does this cryogenic chamber make me look fat?\nno" return"Whatever." end end end Iteration #1

Slide 47

Slide 47 text

class Bob def hey (input ) if input=="Tom-ay-to, tom-aaaah-to." return"Whatever." elsif input == "WATCH OUT!" return "Whoa, chill out!" elsif input == "Does this cryogenic chamber make me look fat?" return "Sure." elsif input== "You are, what, like 15?" return "Sure." elsif input == "Let's go make out behind the gym!" return "Whatever." elsif input == "It's OK if you don't want to go to the DMV." return "Whatever." elsif input == "WHAT THE HELL WERE YOU THINKING?" return "Whoa, chill out!" elsif input == "1, 2, 3 GO!" return "Whoa, chill out!" elsif input =="1, 2, 3" return "Whatever." elsif input=="4?" return "Sure." elsif input == "ZOMG THE %^*@#$(*^ ZOMBIES ARE COMING!!11!!1!" return "Whoa, chill out!" elsif input == "I HATE YOU" return"Whoa, chill out!" elsif input == "Ending with ? means a question." return "Whatever." elsif input== "Wait! Hang on. Are you going to be OK?" return "Sure." elsif input=="" return"Fine. Be that way!" elsif input == " " return "Fine. Be that way!" elsif input == " " return "Fine. Be that way!" elsif input==" " return "Fine. Be that way!" elsif input == "Does this cryogenic chamber make me look fat?\nno" return"Whatever." end end end Iteration #1

Slide 48

Slide 48 text

Iteration #1 class Bob def hey (input ) if input=="Tom-ay-to, tom-aaaah-to." return"Whatever." elsif input == "WATCH OUT!" return "Whoa, chill out!" elsif input == "Does this cryogenic chamber make me look fat?" return "Sure." elsif input== "You are, what, like 15?" return "Sure." elsif input == "Let's go make out behind the gym!" return "Whatever." elsif input == "It's OK if you don't want to go to the DMV." return "Whatever." elsif input == "WHAT THE HELL WERE YOU THINKING?" return "Whoa, chill out!" elsif input == "1, 2, 3 GO!" return "Whoa, chill out!" elsif input =="1, 2, 3" return "Whatever." elsif input=="4?" return "Sure." elsif input == "ZOMG THE %^*@#$(*^ ZOMBIES ARE COMING!!11!!1!" return "Whoa, chill out!" elsif input == "I HATE YOU" return"Whoa, chill out!" elsif input == "Ending with ? means a question." return "Whatever." elsif input== "Wait! Hang on. Are you going to be OK?" return "Sure." elsif input=="" return"Fine. Be that way!" elsif input == " " return "Fine. Be that way!" elsif input == " " return "Fine. Be that way!" elsif input==" " return "Fine. Be that way!" elsif input == "Does this cryogenic chamber make me look fat?\nno" return"Whatever." end end end

Slide 49

Slide 49 text

class Bob def hey(input) if input == "Tom-ay-to, tom-aaaah-to." return "Whatever." elsif input == "WATCH OUT!" return "Whoa, chill out!" elsif input == "Does this cryogenic chamber make me look fat?" return "Sure." elsif input == "You are, what, like 15?" return "Sure." elsif input == "Let's go make out behind the gym!" return "Whatever." elsif input == "It's OK if you don't want to go to the DMV." return "Whatever." elsif input == "WHAT THE HELL WERE YOU THINKING?" return "Whoa, chill out!" elsif input == "1, 2, 3 GO!" return "Whoa, chill out!" elsif input == "1, 2, 3" return "Whatever." elsif input == "4?" return "Sure." elsif input == "ZOMG THE %^*@#$(*^ ZOMBIES ARE COMING!!11!!1!" return "Whoa, chill out!" elsif input == "I HATE YOU" return "Whoa, chill out!" elsif input == "Ending with ? means a question." return "Whatever." elsif input == "Wait! Hang on. Are you going to be OK?" return "Sure." elsif input == "" return "Fine. Be that way!" elsif input == " " return "Fine. Be that way!" elsif input == " " return "Fine. Be that way!" elsif input == " " return "Fine. Be that way!" elsif input == "Does this cryogenic chamber make me look fat?\nno" return "Whatever." end end end Iteration #1 class Bob def hey (input ) if input=="Tom-ay-to, tom-aaaah-to." return"Whatever." elsif input == "WATCH OUT!" return "Whoa, chill out!" elsif input == "Does this cryogenic chamber make me look fat?" return "Sure." elsif input== "You are, what, like 15?" return "Sure." elsif input == "Let's go make out behind the gym!" return "Whatever." elsif input == "It's OK if you don't want to go to the DMV." return "Whatever." elsif input == "WHAT THE HELL WERE YOU THINKING?" return "Whoa, chill out!" elsif input == "1, 2, 3 GO!" return "Whoa, chill out!" elsif input =="1, 2, 3" return "Whatever." elsif input=="4?" return "Sure." elsif input == "ZOMG THE %^*@#$(*^ ZOMBIES ARE COMING!!11!!1!" return "Whoa, chill out!" elsif input == "I HATE YOU" return"Whoa, chill out!" elsif input == "Ending with ? means a question." return "Whatever." elsif input== "Wait! Hang on. Are you going to be OK?" return "Sure." elsif input=="" return"Fine. Be that way!" elsif input == " " return "Fine. Be that way!" elsif input == " " return "Fine. Be that way!" elsif input==" " return "Fine. Be that way!" elsif input == "Does this cryogenic chamber make me look fat?\nno" return"Whatever." end end end

Slide 50

Slide 50 text

take-away #1

Slide 51

Slide 51 text

take-away #1 whitespace is meaningful

Slide 52

Slide 52 text

Iteration #2 class Bob def hey(input) if input == "Tom-ay-to, tom-aaaah-to." return "Whatever." elsif input == "WATCH OUT!" return "Whoa, chill out!" elsif input == "Does this cryogenic chamber make me look fat?" return "Sure." elsif input == "You are, what, like 15?" return "Sure." elsif input == "Let's go make out behind the gym!" return "Whatever." elsif input == "It's OK if you don't want to go to the DMV." return "Whatever." elsif input == "WHAT THE HELL WERE YOU THINKING?" return "Whoa, chill out!" elsif input == "1, 2, 3 GO!" return "Whoa, chill out!" elsif input == "1, 2, 3" return "Whatever." elsif input == "4?" return "Sure."

Slide 53

Slide 53 text

Iteration #2 class Bob def hey(input) if input == "Tom-ay-to, tom-aaaah-to." return "Whatever." elsif input == "WATCH OUT!" return "Whoa, chill out!" elsif input == "Does this cryogenic chamber make me look fat?" return "Sure." elsif input == "You are, what, like 15?" return "Sure." elsif input == "Let's go make out behind the gym!" return "Whatever." elsif input == "It's OK if you don't want to go to the DMV." return "Whatever." elsif input == "WHAT THE HELL WERE YOU THINKING?" return "Whoa, chill out!" elsif input == "1, 2, 3 GO!" return "Whoa, chill out!" elsif input == "1, 2, 3" return "Whatever." elsif input == "4?" return "Sure." elsif input == "ZOMG THE %^*@#$(*^ ZOMBIES ARE COMING!!11!!1!" return "Whoa, chill out!" elsif input == "I HATE YOU" return "Whoa, chill out!" elsif input == "Ending with ? means a question." return "Whatever." elsif input == "Wait! Hang on. Are you going to be OK?" return "Sure." elsif input == "" return "Fine. Be that way!" elsif input == " " return "Fine. Be that way!" elsif input == " " return "Fine. Be that way!" elsif input == " " return "Fine. Be that way!" elsif input == "Does this cryogenic chamber make me look fat?\nno" return "Whatever." end end end

Slide 54

Slide 54 text

Iteration #2 class Bob def hey(input) if input == "Tom-ay-to, tom-aaaah-to." return "Whatever." elsif input == "WATCH OUT!" return "Whoa, chill out!" elsif input == "Does this cryogenic chamber make me look fat?" return "Sure." elsif input == "You are, what, like 15?" return "Sure." elsif input == "Let's go make out behind the gym!" return "Whatever." elsif input == "It's OK if you don't want to go to the DMV." return "Whatever." elsif input == "WHAT THE HELL WERE YOU THINKING?" return "Whoa, chill out!" elsif input == "1, 2, 3 GO!" return "Whoa, chill out!" elsif input == "1, 2, 3" return "Whatever." elsif input == "4?" return "Sure." elsif input == "ZOMG THE %^*@#$(*^ ZOMBIES ARE COMING!!11!!1!" return "Whoa, chill out!" elsif input == "I HATE YOU" return "Whoa, chill out!" elsif input == "Ending with ? means a question." return "Whatever." elsif input == "Wait! Hang on. Are you going to be OK?" return "Sure." elsif input == "" return "Fine. Be that way!" elsif input == " " return "Fine. Be that way!" elsif input == " " return "Fine. Be that way!" elsif input == " " return "Fine. Be that way!" elsif input == "Does this cryogenic chamber make me look fat?\nno" return "Whatever." end end end

Slide 55

Slide 55 text

Iteration #2 class Bob def hey(input) if input == "Tom-ay-to, tom-aaaah-to." return "Whatever." elsif input == "WATCH OUT!" return "Whoa, chill out!" elsif input == "Does this cryogenic chamber make me look fat?" return "Sure." elsif input == "You are, what, like 15?" return "Sure." elsif input == "Let's go make out behind the gym!" return "Whatever." elsif input == "It's OK if you don't want to go to the DMV." return "Whatever." elsif input == "WHAT THE HELL WERE YOU THINKING?" return "Whoa, chill out!" elsif input == "1, 2, 3 GO!" return "Whoa, chill out!" elsif input == "1, 2, 3" return "Whatever." elsif input == "4?" return "Sure." elsif input == "ZOMG THE %^*@#$(*^ ZOMBIES ARE COMING!!11!!1!" return "Whoa, chill out!" elsif input == "I HATE YOU" return "Whoa, chill out!" elsif input == "Ending with ? means a question." return "Whatever." elsif input == "Wait! Hang on. Are you going to be OK?" return "Sure." elsif input == "" return "Fine. Be that way!" elsif input == " " return "Fine. Be that way!" elsif input == " " return "Fine. Be that way!" elsif input == " " return "Fine. Be that way!" elsif input == "Does this cryogenic chamber make me look fat?\nno" return "Whatever." end end end

Slide 56

Slide 56 text

Iteration #2 class Bob def hey(input) if input == "Tom-ay-to, tom-aaaah-to." return "Whatever." elsif input == "WATCH OUT!" return "Whoa, chill out!" elsif input == "Does this cryogenic chamber make me look fat?" return "Sure." elsif input == "You are, what, like 15?" return "Sure." elsif input == "Let's go make out behind the gym!" return "Whatever." elsif input == "It's OK if you don't want to go to the DMV." return "Whatever." elsif input == "WHAT THE HELL WERE YOU THINKING?" return "Whoa, chill out!" elsif input == "1, 2, 3 GO!" return "Whoa, chill out!" elsif input == "1, 2, 3" return "Whatever." elsif input == "4?" return "Sure." elsif input == "ZOMG THE %^*@#$(*^ ZOMBIES ARE COMING!!11!!1!" return "Whoa, chill out!" elsif input == "I HATE YOU" return "Whoa, chill out!" elsif input == "Ending with ? means a question." return "Whatever." elsif input == "Wait! Hang on. Are you going to be OK?" return "Sure." elsif input == "" return "Fine. Be that way!" elsif input == " " return "Fine. Be that way!" elsif input == " " return "Fine. Be that way!" elsif input == " " return "Fine. Be that way!" elsif input == "Does this cryogenic chamber make me look fat?\nno" return "Whatever." end end end

Slide 57

Slide 57 text

Iteration #2 class Bob def hey(input) case input when "Tom-ay-to, tom-aaaah-to." "Whatever." when "WATCH OUT!" "Whoa, chill out!" when "Does this cryogenic chamber make me look fat?" "Sure." when "You are, what, like 15?" "Sure." when "Let's go make out behind the gym!" "Whatever." when "It's OK if you don't want to go to the DMV." "Whatever." when "WHAT THE HELL WERE YOU THINKING?" "Whoa, chill out!" when "1, 2, 3 GO!" "Whoa, chill out!" when "1, 2, 3" "Whatever." when "4?" "Sure." when "ZOMG THE %^*@#$(*^ ZOMBIES ARE COMING!!11!!1!" "Whoa, chill out!" when "Does this cryogenic chamber make me look fat?\nno" "Whatever." when "I HATE YOU" "Whoa, chill out!" when "Ending with ? means a question." "Whatever." when "Wait! Hang on. Are you going to be OK?" "Sure." when "" "Fine. Be that way!" when " " "Fine. Be that way!" when " " "Fine. Be that way!" end end end class Bob def hey(input) if input == "Tom-ay-to, tom-aaaah-to." return "Whatever." elsif input == "WATCH OUT!" return "Whoa, chill out!" elsif input == "Does this cryogenic chamber make me look fat?" return "Sure." elsif input == "You are, what, like 15?" return "Sure." elsif input == "Let's go make out behind the gym!" return "Whatever." elsif input == "It's OK if you don't want to go to the DMV." return "Whatever." elsif input == "WHAT THE HELL WERE YOU THINKING?" return "Whoa, chill out!" elsif input == "1, 2, 3 GO!" return "Whoa, chill out!" elsif input == "1, 2, 3" return "Whatever." elsif input == "4?" return "Sure." elsif input == "ZOMG THE %^*@#$(*^ ZOMBIES ARE COMING!!11!!1!" return "Whoa, chill out!" elsif input == "I HATE YOU" return "Whoa, chill out!" elsif input == "Ending with ? means a question." return "Whatever." elsif input == "Wait! Hang on. Are you going to be OK?" return "Sure." elsif input == "" return "Fine. Be that way!" elsif input == " " return "Fine. Be that way!" elsif input == " " return "Fine. Be that way!" elsif input == " " return "Fine. Be that way!" elsif input == "Does this cryogenic chamber make me look fat?\nno" return "Whatever." end end end

Slide 58

Slide 58 text

take-away #2

Slide 59

Slide 59 text

take-away #2 minimize boilerplate

Slide 60

Slide 60 text

Iteration #3 class Bob def hey(input) case input when "Tom-ay-to, tom-aaaah-to." "Whatever." when "WATCH OUT!" "Whoa, chill out!" when "Does this cryogenic chamber make me look fat?" "Sure." when "You are, what, like 15?" "Sure." when "Let's go make out behind the gym!" "Whatever." when "It's OK if you don't want to go to the DMV." "Whatever." when "WHAT THE HELL WERE YOU THINKING?" "Whoa, chill out!" when "1, 2, 3 GO!" "Whoa, chill out!" when "1, 2, 3" "Whatever." when "4?"

Slide 61

Slide 61 text

Iteration #3 case input when "Tom-ay-to, tom-aaaah-to." "Whatever." when "WATCH OUT!" "Whoa, chill out!" when "Does this cryogenic chamber make me look fat?" "Sure." when "You are, what, like 15?" "Sure." when "Let's go make out behind the gym!" "Whatever." when "It's OK if you don't want to go to the DMV." "Whatever." when "WHAT THE HELL WERE YOU THINKING?" "Whoa, chill out!" when "1, 2, 3 GO!" "Whoa, chill out!" when "1, 2, 3" "Whatever." when "4?" "Sure." when "ZOMG THE %^*@#$(*^ ZOMBIES ARE COMING!!11!!1!" "Whoa, chill out!" when "Does this cryogenic chamber make me look fat?\nno" "Whatever." when "I HATE YOU" "Whoa, chill out!" when "Ending with ? means a question." "Whatever." when "Wait! Hang on. Are you going to be OK?" "Sure." when "" "Fine. Be that way!" when " " "Fine. Be that way!" when " " "Fine. Be that way!" end

Slide 62

Slide 62 text

Iteration #3 case input when "Tom-ay-to, tom-aaaah-to." "Whatever." when "WATCH OUT!" "Whoa, chill out!" when "Does this cryogenic chamber make me look fat?" "Sure." when "You are, what, like 15?" "Sure." when "Let's go make out behind the gym!" "Whatever." when "It's OK if you don't want to go to the DMV." "Whatever." when "WHAT THE HELL WERE YOU THINKING?" "Whoa, chill out!" when "1, 2, 3 GO!" "Whoa, chill out!" when "1, 2, 3" "Whatever." when "4?" "Sure." when "ZOMG THE %^*@#$(*^ ZOMBIES ARE COMING!!11!!1!" "Whoa, chill out!" when "Does this cryogenic chamber make me look fat?\nno" "Whatever." when "I HATE YOU" "Whoa, chill out!" when "Ending with ? means a question." "Whatever." when "Wait! Hang on. Are you going to be OK?" "Sure." when "" "Fine. Be that way!" when " " "Fine. Be that way!" when " " "Fine. Be that way!" end

Slide 63

Slide 63 text

Iteration #3 case input when "Tom-ay-to, tom-aaaah-to." "Whatever." when "WATCH OUT!" "Whoa, chill out!" when "Does this cryogenic chamber make me look fat?" "Sure." when "You are, what, like 15?" "Sure." when "Let's go make out behind the gym!" "Whatever." when "It's OK if you don't want to go to the DMV." "Whatever." when "WHAT THE HELL WERE YOU THINKING?" "Whoa, chill out!" when "1, 2, 3 GO!" "Whoa, chill out!" when "1, 2, 3" "Whatever." when "4?" "Sure." when "ZOMG THE %^*@#$(*^ ZOMBIES ARE COMING!!11!!1!" "Whoa, chill out!" when "Does this cryogenic chamber make me look fat?\nno" "Whatever." when "I HATE YOU" "Whoa, chill out!" when "Ending with ? means a question." "Whatever." when "Wait! Hang on. Are you going to be OK?" "Sure." when "" "Fine. Be that way!" when " " "Fine. Be that way!" when " " "Fine. Be that way!" end

Slide 64

Slide 64 text

Iteration #3 case input when "Tom-ay-to, tom-aaaah-to." "Whatever." when "WATCH OUT!" "Whoa, chill out!" when "Does this cryogenic chamber make me look fat?" "Sure." when "You are, what, like 15?" "Sure." when "Let's go make out behind the gym!" "Whatever." when "It's OK if you don't want to go to the DMV." "Whatever." when "WHAT THE HELL WERE YOU THINKING?" "Whoa, chill out!" when "1, 2, 3 GO!" "Whoa, chill out!" when "1, 2, 3" "Whatever." when "4?" "Sure." when "ZOMG THE %^*@#$(*^ ZOMBIES ARE COMING!!11!!1!" "Whoa, chill out!" when "Does this cryogenic chamber make me look fat?\nno" "Whatever." when "I HATE YOU" "Whoa, chill out!" when "Ending with ? means a question." "Whatever." when "Wait! Hang on. Are you going to be OK?" "Sure." when "" "Fine. Be that way!" when " " "Fine. Be that way!" when " " "Fine. Be that way!" end

Slide 65

Slide 65 text

Iteration #3 case input when "Tom-ay-to, tom-aaaah-to." "Whatever." when "WATCH OUT!" "Whoa, chill out!" when "Does this cryogenic chamber make me look fat?" "Sure." when "You are, what, like 15?" "Sure." when "Let's go make out behind the gym!" "Whatever." when "It's OK if you don't want to go to the DMV." "Whatever." when "WHAT THE HELL WERE YOU THINKING?" "Whoa, chill out!" when "1, 2, 3 GO!" "Whoa, chill out!" when "1, 2, 3" "Whatever." when "4?" "Sure." when "ZOMG THE %^*@#$(*^ ZOMBIES ARE COMING!!11!!1!" "Whoa, chill out!" when "Does this cryogenic chamber make me look fat?\nno" "Whatever." when "I HATE YOU" "Whoa, chill out!" when "Ending with ? means a question." "Whatever." when "Wait! Hang on. Are you going to be OK?" "Sure." when "" "Fine. Be that way!" when " " "Fine. Be that way!" when " " "Fine. Be that way!" end

Slide 66

Slide 66 text

Iteration #3 case input when "Tom-ay-to, tom-aaaah-to." "Whatever." when "WATCH OUT!" "Whoa, chill out!" when "Does this cryogenic chamber make me look fat?" "Sure." when "You are, what, like 15?" "Sure." when "Let's go make out behind the gym!" "Whatever." when "It's OK if you don't want to go to the DMV." "Whatever." when "WHAT THE HELL WERE YOU THINKING?" "Whoa, chill out!" when "1, 2, 3 GO!" "Whoa, chill out!" when "1, 2, 3" "Whatever." when "4?" "Sure." when "ZOMG THE %^*@#$(*^ ZOMBIES ARE COMING!!11!!1!" "Whoa, chill out!" when "Does this cryogenic chamber make me look fat?\nno" "Whatever." when "I HATE YOU" "Whoa, chill out!" when "Ending with ? means a question." "Whatever." when "Wait! Hang on. Are you going to be OK?" "Sure." when "" "Fine. Be that way!" when " " "Fine. Be that way!" when " " "Fine. Be that way!" end

Slide 67

Slide 67 text

Iteration #3 class Bob def hey(input) case input when "Tom-ay-to, tom-aaaah-to.", "Let's go make out behind the gym! "Whatever." when "WATCH OUT!", "WHAT THE HELL WERE YOU THINKING?", "1, 2, 3 GO! "Whoa, chill out!" when "Does this cryogenic chamber make me look fat?", "You are, wha "Sure." when "", " ", " " "Fine. Be that way!" end end end

Slide 68

Slide 68 text

Iteration #3 ic chamber make me look fat?\nno", "Ending with ? means a question."

Slide 69

Slide 69 text

there I fixed it!

Slide 70

Slide 70 text

take-away #3

Slide 71

Slide 71 text

take-away #3 don’t repeat yourself (DRY)

Slide 72

Slide 72 text

Iteration #4 class Bob def hey(input) case input when "Tom-ay-to, tom-aaaah-to.", "Let's go make out behind the gym! "Whatever." when "WATCH OUT!", "WHAT THE HELL WERE YOU THINKING?", "1, 2, 3 GO! "Whoa, chill out!" when "Does this cryogenic chamber make me look fat?", "You are, wha "Sure." when "", " ", " " "Fine. Be that way!" end end end

Slide 73

Slide 73 text

Iteration #4 class Bob def hey(input) case input when "Tom-ay-to, tom-aaaah-to.", "Let's go make out behind the gym!", "It's OK if you don't want to go to the DMV.", "1, 2, 3", "Does this cryogenic chamber make me look fat?\nno", "Ending with ? means a question." "Whatever." when "WATCH OUT!", "WHAT THE HELL WERE YOU THINKING?", "1, 2, 3 GO!", "ZOMG THE %^*@#$(*^ ZOMBIES ARE COMING!!11!!1!", "I HATE YOU" "Whoa, chill out!" when "Does this cryogenic chamber make me look fat?", "You are, what, like 15?", "4?", "Wait! Hang on. Are you going to be OK?" "Sure." when "", " ", " " "Fine. Be that way!" end end end

Slide 74

Slide 74 text

Iteration #4 "Sure." when "", " ", " " "Fine. Be that way!" end end end

Slide 75

Slide 75 text

Iteration #4 "Whoa, chill out!" when "Does this cryogenic chamber make me look fat?", "You are, what, like 15?", "4?", "Wait! Hang on. Are you going to be OK?" "Sure." when "",

Slide 76

Slide 76 text

Iteration #4 "Whatever." when "WATCH OUT!", "WHAT THE HELL WERE YOU THINKING?", "1, 2, 3 GO!", "ZOMG THE %^*@#$(*^ ZOMBIES ARE COMING!!11!!1!", "I HATE YOU" "Whoa, chill out!" when "Does this cryogenic chamber make me look fat?",

Slide 77

Slide 77 text

Iteration #4 case input when "Tom-ay-to, tom-aaaah-to.", "Let's go make out behind the gym!", "It's OK if you don't want to go to the DMV.", "1, 2, 3", "Does this cryogenic chamber make me look fat?\nno", "Ending with ? means a question." "Whatever." when "WATCH OUT!",

Slide 78

Slide 78 text

Iteration #5 class Bob def hey(input) return "Whoa, chill out!" if input =~ /\A[\dA-Z\s\W]+\z/ and input =~ /[A-Z]/ return "Sure." if input.split("").last == "?" return "Fine. Be that way!" if input.strip == "" "Whatever." end end

Slide 79

Slide 79 text

take-away #4

Slide 80

Slide 80 text

take-away #4 find the abstraction

Slide 81

Slide 81 text

Iteration #5 class Bob def hey(input) return "Whoa, chill out!" if input =~ /\A[\dA-Z\s\W]+\z/ and input =~ /[A-Z]/ return "Sure." if input.split("").last == "?" return "Fine. Be that way!" if input.strip == "" "Whatever." end end

Slide 82

Slide 82 text

Iteration #5 class Bob def hey(input) return "Whoa, chill out!" if input =~ /\A[\dA-Z\s\W]+\z/ and input =~ /[A-Z]/ return "Sure." if input.split("").last == "?" return "Fine. Be that way!" if input.strip == "" "Whatever." end end

Slide 83

Slide 83 text

Iteration #5 input =~ /\A[\dA-Z\s\W]+\z/ and input =~ /[A-Z]/

Slide 84

Slide 84 text

input == input.upcase Iteration #5

Slide 85

Slide 85 text

input == input.upcase and input != input.downcase Iteration #5

Slide 86

Slide 86 text

Iteration #5 class Bob def hey(input) return "Whoa, chill out!" if input == input.upcase and input != input.downcase return "Sure." if input.split("").last == "?" return "Fine. Be that way!" if input.strip == "" "Whatever." end end

Slide 87

Slide 87 text

Iteration #5 input.split("").last == "?"

Slide 88

Slide 88 text

Iteration #5 input.end_with?("?")

Slide 89

Slide 89 text

Iteration #5 class Bob def hey(input) return "Whoa, chill out!" if input == input.upcase and input != input.downcase return "Sure." if input.end_with?("?") return "Fine. Be that way!" if input.strip == "" "Whatever." end end

Slide 90

Slide 90 text

Iteration #5 input.strip == ""

Slide 91

Slide 91 text

input.strip.empty? Iteration #5

Slide 92

Slide 92 text

take-away #5

Slide 93

Slide 93 text

take-away #5 seek fluency

Slide 94

Slide 94 text

Iteration #6 class Bob def hey(input) return "Whoa, chill out!" if input == input.upcase and input != input.downcase return "Sure." if input.end_with?("?") return "Fine. Be that way!" if input.strip.empty? "Whatever." end end

Slide 95

Slide 95 text

input == input.upcase and input != input.downcase So expressive!

Slide 96

Slide 96 text

and control flow operator

Slide 97

Slide 97 text

&& boolean operator

Slide 98

Slide 98 text

boolean vs control flow hungry? && thirsty?

Slide 99

Slide 99 text

rich? && famous? boolean vs control flow

Slide 100

Slide 100 text

sing and dance boolean vs control flow

Slide 101

Slide 101 text

rise and shine boolean vs control flow

Slide 102

Slide 102 text

boolean vs control flow if hungry? && thirsty? eat and drink and be_merry! end

Slide 103

Slide 103 text

Iteration #6 class Bob def hey(input) return "Whoa, chill out!" if input == input.upcase and input != input.downcase return "Sure." if input.end_with?("?") return "Fine. Be that way!" if input.strip.empty? "Whatever." end end

Slide 104

Slide 104 text

Iteration #6 class Bob def hey(input) return "Whoa, chill out!" if input == input.upcase && input != input.downcase return "Sure." if input.end_with?("?") return "Fine. Be that way!" if input.strip.empty? "Whatever." end end

Slide 105

Slide 105 text

take-away #6

Slide 106

Slide 106 text

take-away #6 familiar isn’t always correct

Slide 107

Slide 107 text

Iteration #7 class Bob def hey(input) return "Whoa, chill out!" if input == input.upcase && input != input.downcase return "Sure." if input.end_with?("?") return "Fine. Be that way!" if input.strip.empty? "Whatever." end end

Slide 108

Slide 108 text

Iteration #7 class Bob def hey(input) return "Whoa, chill out!" if input == input.upcase && input != input.downcase return "Sure." if input.end_with?("?") return "Fine. Be that way!" if input.strip.empty? "Whatever." end end

Slide 109

Slide 109 text

Iteration #7 class Bob def hey(input) case when input == input.upcase && input != input.downcase "Whoa, chill out!" when input.end_with?("?") "Sure." when input.strip.empty? "Fine. Be that way!" else "Whatever." end end end

Slide 110

Slide 110 text

take-away #7

Slide 111

Slide 111 text

take-away #7 shorter is better, unless it means something else

Slide 112

Slide 112 text

Iteration #8 class Bob def hey(input) case when input == input.upcase && input != input.downcase "Whoa, chill out!" when input.end_with?("?") "Sure." when input.strip.empty? "Fine. Be that way!" else "Whatever." end end end

Slide 113

Slide 113 text

Iteration #8 class Bob def hey(input) @input = input case when all_caps? then "Whoa, chill out!" when question? then "Sure." when empty? then "Fine. Be that way!" else "Whatever." end end def empty? @input.strip.empty? end def question? @input.end_with?("?") end def all_caps? @input == @input.upcase && @input != @input.downcase end end

Slide 114

Slide 114 text

a what-now? all_caps? question? empty?

Slide 115

Slide 115 text

a what-now? all_caps? question? empty? ➔ shout?

Slide 116

Slide 116 text

a what-now? all_caps? question? empty? ➔ shout? ➔ silence?

Slide 117

Slide 117 text

a what-now? shout? question? silence?

Slide 118

Slide 118 text

take-away #8

Slide 119

Slide 119 text

take-away #8 hide the fiddly details

Slide 120

Slide 120 text

Iteration #9 class Bob def hey(input) @input = input case when shout? then "Whoa, chill out!" when question? then "Sure." when silence? then "Fine. Be that way!" else "Whatever." end end def silence? @input.strip.empty? end def question? @input.end_with?("?") end def shout? @input == @input.upcase && @input != @input.downcase end end

Slide 121

Slide 121 text

Iteration #9 class Bob def hey(input) @input = input case when shout? then "Whoa, chill out!" when question? then "Sure." when silence? then "Fine. Be that way!" else "Whatever." end end def silence? @input.strip.empty? end def question? @input.end_with?("?") end def shout? @input == @input.upcase && @input != @input.downcase end end

Slide 122

Slide 122 text

Iteration #9 class Bob def hey(input) @input = input case when shout? then "Whoa, chill out!" when question? then "Sure." when silence? then "Fine. Be that way!" else "Whatever." end end def silence? @input.strip.empty? end def question? @input.end_with?("?") end def shout? @input == @input.upcase && @input != @input.downcase end end

Slide 123

Slide 123 text

Iteration #9 class Bob def hey(input) @input = input case when shout? then "Whoa, chill out!" when question? then "Sure." when silence? then "Fine. Be that way!" else "Whatever." end end def silence? @input.strip.empty? end def question? @input.end_with?("?") end def shout? @input == @input.upcase && @input != @input.downcase end end

Slide 124

Slide 124 text

Iteration #9 class Bob def hey(input) @input = input case when shout? then "Whoa, chill out!" when question? then "Sure." when silence? then "Fine. Be that way!" else "Whatever." end end def silence? @input.strip.empty? end def question? @input.end_with?("?") end def shout? @input == @input.upcase && @input != @input.downcase end end

Slide 125

Slide 125 text

Iteration #9 class Bob def hey(input) @input = input case when shout? then "Whoa, chill out!" when question? then "Sure." when silence? then "Fine. Be that way!" else "Whatever." end end def silence? @input.strip.empty? end def question? @input.end_with?("?") end def shout? @input == @input.upcase && @input != @input.downcase end end

Slide 126

Slide 126 text

Iteration #9 class Bob def hey(input) @input = input case when shout? then "Whoa, chill out!" when question? then "Sure." when silence? then "Fine. Be that way!" else "Whatever." end end private def silence? @input.strip.empty? end def question? @input.end_with?("?") end def shout? @input == @input.upcase && @input != @input.downcase end end

Slide 127

Slide 127 text

take-away #9

Slide 128

Slide 128 text

take-away #9 make the public API coherent

Slide 129

Slide 129 text

Iteration #10 class Bob def hey(input) @input = input case when shout? then "Whoa, chill out!" when question? then "Sure." when silence? then "Fine. Be that way!" else "Whatever." end end private def silence? @input.strip.empty? end def question? @input.end_with?("?") end def shout? @input == @input.upcase && @input != @input.downcase end end

Slide 130

Slide 130 text

Iteration #10 class Bob def hey(input) @input = input case when shout? then "Whoa, chill out!" when question? then "Sure." when silence? then "Fine. Be that way!" else "Whatever." end end private def silence? @input.strip.empty? end def question? @input.end_with?("?") end def shout? @input == @input.upcase && @input != @input.downcase end end

Slide 131

Slide 131 text

Iteration #10 class Bob def hey(input) @input = input case when shout? then "Whoa, chill out!" when question? then "Sure." when silence? then "Fine. Be that way!" else "Whatever." end end private attr_reader :input def silence? input.strip.empty? end def question? input.end_with?("?") end def shout? input == input.upcase && input != input.downcase end end

Slide 132

Slide 132 text

take-away #10

Slide 133

Slide 133 text

take-away #10 send a message

Slide 134

Slide 134 text

Iteration #11 class Bob def hey(input) @input = input case when shout? then "Whoa, chill out!" when question? then "Sure." when silence? then "Fine. Be that way!" else "Whatever." end end private attr_reader :input def silence? input.strip.empty? end def question? input.end_with?("?") end def shout? input == input.upcase && input != input.downcase end end

Slide 135

Slide 135 text

confusion ensues B A

Slide 136

Slide 136 text

confusion ensues B A "ARE YOU CRAZY?"

Slide 137

Slide 137 text

"ARE YOU CRAZY?" @input confusion ensues B A "ARE YOU CRAZY?"

Slide 138

Slide 138 text

"ARE YOU CRAZY?" @input confusion ensues B A "ARE YOU CRAZY?" C "You’re late."

Slide 139

Slide 139 text

@input "You’re late." confusion ensues B A "ARE YOU CRAZY?" C "You’re late."

Slide 140

Slide 140 text

confusion ensues B A

Slide 141

Slide 141 text

@input "You’re late." confusion ensues B A

Slide 142

Slide 142 text

@input "You’re late." confusion ensues "Whatever." B A

Slide 143

Slide 143 text

private attr_reader :input def silence? input.strip.empty? end ... Iteration #11

Slide 144

Slide 144 text

private attr_reader :input def silence? input.strip.empty? end ... Iteration #11 private def silence? ->(s) { s.strip.empty? } end ...

Slide 145

Slide 145 text

take-away #11

Slide 146

Slide 146 text

take-away #11 fleeting state doesn’t belong in instance variables

Slide 147

Slide 147 text

Iteration #12 class Bob def hey(input) case input when shout? then "Whoa, chill out!" when question? then "Sure." when silence? then "Fine. Be that way!" else "Whatever." end end private def silence? ->(s) { s.strip.empty? } end def question? ->(s) { s.end_with?("?") } end def shout? ->(s) { s == s.upcase && s != s.downcase } end end

Slide 148

Slide 148 text

special case case age when ->(i) { i < 13 } then "kiddo" when ->(i) { i % 25 == 0 } then "quarter" when ->(i) { i % 10 == 0 } then "decade" end

Slide 149

Slide 149 text

Iteration #12 class Bob def hey(input) case input when shout? then "Whoa, chill out!" when question? then "Sure." when silence? then "Fine. Be that way!" else "Whatever." end end private def silence? ->(s) { s.strip.empty? } end def question? ->(s) { s.end_with?("?") } end def shout? ->(s) { s == s.upcase && s != s.downcase } end end

Slide 150

Slide 150 text

truth def question? ->(s) { s.end_with?("?") } end

Slide 151

Slide 151 text

Proc.new{ false } truth

Slide 152

Slide 152 text

truth

Slide 153

Slide 153 text

!!Proc.new{ false } # => true truth

Slide 154

Slide 154 text

private def silence? ->(s) { s.strip.empty? } end def question? ->(s) { s.end_with?("?") } end def shout? ->(s) { s == s.upcase && s != s.downcase } end Iteration #12

Slide 155

Slide 155 text

private def silence? ->(s) { s.strip.empty? } end def question? ->(s) { s.end_with?("?") } end def shout? ->(s) { s == s.upcase && s != s.downcase } end Iteration #12 private def silence?(s) s.strip.empty? end def question?(s) s.end_with?("?") end def shout?(s) s == s.upcase && s != s.downcase end

Slide 156

Slide 156 text

take-away #12

Slide 157

Slide 157 text

take-away #12 don’t lie

Slide 158

Slide 158 text

Iteration #13 class Bob def hey(input) case when shout?(input) then "Whoa, chill out!" when question?(input) then "Sure." when silence?(input) then "Fine. Be that way!" else "Whatever." end end private def silence?(s) s.strip.empty? end def question?(s) s.end_with?("?") end def shout?(s) s == s.upcase && s != s.downcase end end

Slide 159

Slide 159 text

Iteration #13 class Bob def hey(input) case when shout?(input) then "Whoa, chill out!" when question?(input) then "Sure." when silence?(input) then "Fine. Be that way!" else "Whatever." end end private def silence?(s) s.strip.empty? end def question?(s) s.end_with?("?") end def shout?(s) s == s.upcase && s != s.downcase end end

Slide 160

Slide 160 text

Iteration #13 class Bob def hey(input) case when shout?(input) then "Whoa, chill out!" when question?(input) then "Sure." when silence?(input) then "Fine. Be that way!" else "Whatever." end end private def silence?(s) s.strip.empty? end def question?(s) s.end_with?("?") end def shout?(s) s == s.upcase && s != s.downcase end end

Slide 161

Slide 161 text

Iteration #13 class Bob def hey(input) case when shout?(input) then "Whoa, chill out!" when question?(input) then "Sure." when silence?(input) then "Fine. Be that way!" else "Whatever." end end private def silence?(s) s.strip.empty? end def question?(s) s.end_with?("?") end def shout?(s) s == s.upcase && s != s.downcase end end

Slide 162

Slide 162 text

Iteration #13 class Bob def hey(input) case when input.shout? then "Whoa, chill out!" when input.question? then "Sure." when input.silence? then "Fine. Be that way!" else "Whatever." end end end class String def silence? strip.empty? end def question? end_with?("?") end def shout? self == upcase && self != downcase end end

Slide 163

Slide 163 text

take-away #13

Slide 164

Slide 164 text

take-away #13 make your objects cohesive

Slide 165

Slide 165 text

Iteration #14 class Bob def hey(input) case when input.shout? then "Whoa, chill out!" when input.question? then "Sure." when input.silence? then "Fine. Be that way!" else "Whatever." end end end class String def silence? strip.empty? end def question? end_with?("?") end def shout? self == upcase && self != downcase end end

Slide 166

Slide 166 text

String API

Slide 167

Slide 167 text

String API #downcase #gsub #reverse #scan #squeeze #to_i ...

Slide 168

Slide 168 text

String API #downcase #gsub #reverse #scan #squeeze #to_i ... #question? #shout? #silence?

Slide 169

Slide 169 text

Iteration #14 class Bob def hey(input) case when input.shout? then "Whoa, chill out!" when input.question? then "Sure." when input.silence? then "Fine. Be that way!" else "Whatever." end end end class String def silence? strip.empty? end def question? end_with?("?") end def shout? self == upcase && self != downcase end end

Slide 170

Slide 170 text

Iteration #14 class Bob def hey(input) input = Input.new(input) case when input.shout? then "Whoa, chill out!" when input.question? then "Sure." when input.silence? then "Fine. Be that way!" else "Whatever." end end end class Input < String def silence? strip.empty? end def question? end_with?("?") end def shout? self == upcase && self != downcase end end

Slide 171

Slide 171 text

take-away #14

Slide 172

Slide 172 text

take-away #14 no, really, make ALL your objects cohesive

Slide 173

Slide 173 text

Iteration #15 class Bob def hey(input) input = Input.new(input) case when input.shout? then "Whoa, chill out!" when input.question? then "Sure." when input.silence? then "Fine. Be that way!" else "Whatever." end end end class Input < String def silence? strip.empty? end def question? end_with?("?") end def shout? self == upcase && self != downcase end end

Slide 174

Slide 174 text

Input API #downcase #gsub #reverse #scan #squeeze #to_i ... #question? #shout? #silence?

Slide 175

Slide 175 text

class DazzlingString < String def sparkle "**;* #{self} **;**" end end beware!

Slide 176

Slide 176 text

s = DazzlingString.new("unicorn") beware!

Slide 177

Slide 177 text

beware!

Slide 178

Slide 178 text

beware! s.sparkle # => **;* unicorn **;**

Slide 179

Slide 179 text

beware! s.sparkle # => **;* unicorn **;** s.upcase # => UNICORN

Slide 180

Slide 180 text

beware! s.sparkle # => **;* unicorn **;** s.upcase # => UNICORN s << 's' # => "unicorns"

Slide 181

Slide 181 text

beware! s.sparkle # => **;* unicorn **;** s.upcase # => UNICORN s << 's' # => "unicorns" s.sparkle # => **;* unicorns **;**

Slide 182

Slide 182 text

beware!

Slide 183

Slide 183 text

s1 = DazzlingString.new("unicorn") beware!

Slide 184

Slide 184 text

s1 = DazzlingString.new("unicorn") s2 = DazzlingString.new("rainbow") beware!

Slide 185

Slide 185 text

beware!

Slide 186

Slide 186 text

s1.sparkle # => **;* unicorn **;** s2.sparkle # => **;* rainbow **;** beware!

Slide 187

Slide 187 text

beware!

Slide 188

Slide 188 text

beware! s3 = s1 + s2 # => "unicornrainbow"

Slide 189

Slide 189 text

beware! s3.sparkle # => undefined method `sparkle' for "unicornrainbow":String (NoMethodError) s3 = s1 + s2 # => "unicornrainbow"

Slide 190

Slide 190 text

Iteration #15 class Bob # ... end class Input < String def silence? strip.empty? end def question? end_with?("?") end def shout? self == upcase && self != downcase end end

Slide 191

Slide 191 text

Iteration #15 class Bob # ... end class Input attr_reader :input def initialize(input) @input = input end def silence? input.strip.empty? end def question? input.end_with?("?") end def shout? input == input.upcase && input != input.downcase end end

Slide 192

Slide 192 text

Input API #question? #shout? #silence?

Slide 193

Slide 193 text

Input API #question? #shout? #silence? #downcase #gsub #reverse #scan #squeeze #to_i ...

Slide 194

Slide 194 text

take-away #15

Slide 195

Slide 195 text

take-away #15 no, really, seriously, f’reals make your objects cohesive

Slide 196

Slide 196 text

Iteration #16 class Bob def hey(input) input = Input.new(input) case # ... end end end class Input attr_reader :input def initialize(input) @input = input end def silence? input.strip.empty? end def question? input.end_with?("?") end def shout? input == input.upcase && input != input.downcase end end

Slide 197

Slide 197 text

Iteration #16 class Bob def hey(input) input = Input.new(input) case # ... end end end class Input attr_reader :input def initialize(input) @input = input end def silence? input.strip.empty? end def question? input.end_with?("?") end def shout? input == input.upcase && input != input.downcase end end

Slide 198

Slide 198 text

naming class String # ... end

Slide 199

Slide 199 text

naming class Input # ... end

Slide 200

Slide 200 text

naming class Analyzer # ... end

Slide 201

Slide 201 text

naming class Parser # ... end

Slide 202

Slide 202 text

naming class Classifier # ... end

Slide 203

Slide 203 text

naming class Message # ... end

Slide 204

Slide 204 text

naming class Comment # ... end

Slide 205

Slide 205 text

naming class Statement # ... end

Slide 206

Slide 206 text

naming class Utterance # ... end

Slide 207

Slide 207 text

naming class Confrontation # ... end

Slide 208

Slide 208 text

naming class Drivel # ... end

Slide 209

Slide 209 text

naming class Blathering # ... end

Slide 210

Slide 210 text

naming class Interpretation # ... end

Slide 211

Slide 211 text

naming class Tone # ... end

Slide 212

Slide 212 text

naming class Perception # ... end

Slide 213

Slide 213 text

point of view shout? question? silence?

Slide 214

Slide 214 text

point of view shout? question? silence? ➔ freaking_out? ➔ dumb_question? ➔ cold_shoulder?

Slide 215

Slide 215 text

naming class Remark # ... end

Slide 216

Slide 216 text

Iteration #16 class Bob def hey(remark) remark = Remark.new(remark) case # ... end end end class Remark attr_reader :remark def initialize(remark) @remark = remark end def silence? remark.strip.empty? end def question? remark.end_with?("?") end def shout? remark == remark.upcase && remark != remark.downcase end end

Slide 217

Slide 217 text

Iteration #16 class Bob def hey(remark) remark = Remark.new(remark) case # ... end end end class Remark attr_reader :remark def initialize(remark) @remark = remark end def silence? remark.strip.empty? end def question? remark.end_with?("?") end def shout? remark == remark.upcase && remark != remark.downcase end end

Slide 218

Slide 218 text

echoes remark = Remark.new(remark) remark.remark

Slide 219

Slide 219 text

echoes host = host.host if host.host?

Slide 220

Slide 220 text

echoes member.member.member

Slide 221

Slide 221 text

echoes var srcData = data; if (data.data && data.data.data) { data = data.data.data; } else if (data.data) { data = data.data; } if (!data) { return; }

Slide 222

Slide 222 text

echoes remark = Remark.new(remark) remark.remark

Slide 223

Slide 223 text

echoes remark = Remark.new(text) remark.text

Slide 224

Slide 224 text

take-away #16

Slide 225

Slide 225 text

take-away #16 naming is hard

Slide 226

Slide 226 text

Final Solution class Bob def hey(text) remark = Remark.new(text) case # ... end end end class Remark attr_reader :text def initialize(text) @text = text end def silence? text.strip.empty? end def question? text.end_with?("?") end def shout? text == text.upcase && text != text.downcase end end case when remark.shout? then "Whoa, chill out!" when remark.question? then "Sure." when remark.silence? then "Fine. Be that way!" else "Whatever." end

Slide 227

Slide 227 text

class Bob def hey (input ) if input=="Tom-ay-to, tom-aaaah-to." return"Whatever." elsif input == "WATCH OUT!" return "Whoa, chill out!" elsif input == "Does this cryogenic chamber make me look fat?" return "Sure." elsif input== "You are, what, like 15?" return "Sure." elsif input == "Let's go make out behind the gym!" return "Whatever." elsif input == "It's OK if you don't want to go to the DMV." return "Whatever." Initial Solution

Slide 228

Slide 228 text

practice toy problems

Slide 229

Slide 229 text

<3 thank you

Slide 230

Slide 230 text

credits Simple Made Easy http://www.infoq.com/presentations/Simple-Made-Easy Rich Hickey 5 elements of Effective Thinking Michael Starbird, Edward Burger Smalltalk Implementation Patterns Kent Beck Mark by Mark http://vimeo.com/79530470 Sarah Gray

Slide 231

Slide 231 text

The Devil is in the Details Katrina Owen @kytrinyx http://exercism.io