$30 off During Our Annual Pro Sale. View Details »

Ruby Book Club LIVE

Ruby Book Club LIVE

Hello and welcome to the Ruby Book Club! We’re delighted that you could join us.

Today we’re starting with section 4.9 in Avdi Grimm’s ‘Confident Ruby’: Replace “string typing” with classes.

As always, it doesn’t matter if you haven’t found time to do the reading. At the Ruby Book Club, we like to make sure that everyone is on the same page.

Nadia Odunayo

July 11, 2016

More Decks by Nadia Odunayo

Other Decks in Technology


  1. Ruby Book Club LIVE Nadia Odunayo @nodunayo @rubybookclub

  2. 1 hour of a Ruby book each week

  3. @saronyitbarek codenewbie.org

  4. @nodunayo ignition.works

  5. None
  6. 4.9 Replace “string typing” with classes

  7. Interactive!

  8. What did you make of the reading?

  9. Who’s done the reading?

  10. None
  11. None
  12. Let’s get started!

  13. “The string is a stark data structure…a perfect vehicle for

    hiding information.” — Alan Perlis p.84
  14. Alan J. Perlis (April 1, 1922 – February 7, 1990)

  15. String Typing

  16. Replace strings that have special meanings with user-defined types.” p.84

  17. Input data is represented as a specially-formatted String. p.84

  18. Input data is represented as a specially-formatted String. There are

    numerous case statements switching on the content of the String. p.84
  19. Polymorphism

  20. p.85

  21. None
  22. None
  23. None
  24. None
  25. None
  26. None
  27. None
  28. Can you spot any problems with this code?

  29. None
  30. None
  31. None
  32. p.87

  33. light = TrafficLight.new p.87

  34. light = TrafficLight.new light.change_to(“PROCEED”) p.87

  35. light = TrafficLight.new light.change_to(“PROCEED”) puts “Next state: #{light.next_state.inspect}” p.87

  36. Next state: nil

  37. None
  38. Next state: nil

  39. None of the case statements end with else clauses. p.87

  40. None
  41. None
  42. Something doesn’t feel right…

  43. …so what can we do about it?

  44. What if we represented traffic light states as objects?

  45. None
  46. None
  47. None
  48. None
  49. So, let’s get rid of that other case statement…

  50. p.92

  51. Subclasses

  52. None
  53. None
  54. None
  55. Conclusion

  56. There were repetitive case statements all switching on the same

    variable. p.96
  57. It was too easy to introduce an invalid value for

    the @state variable. p.96
  58. “traffic light state” p.96

  59. “The key to working productively in an OO language is

    to make the type system and polymorphic method dispatch do the work for you.” — Avdi Grimm p.96
  60. Wrap up

  61. See you next week?

  62. Do I need to convince you to come back next

  63. Here’s the thing…

  64. How do we level up as developers?

  65. Read books

  66. How many technical books have you finished?

  67. Being in a book club is the answer.

  68. Focus

  69. Review

  70. Fun

  71. Being in a book club is the answer.

  72. Being in the Ruby Book Club is the answer.

  73. None
  74. CRBOOKCLUB 20% off confidentruby.com

  75. Subscribe

  76. rubybookclub.com

  77. @rubybookclub

  78. See you next week.

  79. See you next week. Nadia Odunayo @nodunayo @rubybookclub Thank you!