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

The Case of the Missing Method — A Ruby Mystery...

The Case of the Missing Method — A Ruby Mystery Story

Business is slow for Ruby Private Investigator, Deirdre Bug. She’s on the verge of switching industry when she gets a call from an anxious young man. "Some class methods have gone missing," he tells her breathlessly. "I need your help."

Deirdre takes the case and begins exploring Ruby objects behind the scenes. Though she thinks she's on familiar ground — Ruby's object model, method lookup — she's about to discover that she really has no clue.

Nadia Odunayo

February 07, 2019
Tweet

More Decks by Nadia Odunayo

Other Decks in Programming

Transcript

  1. "

  2. "

  3. $

  4. Jenny • 27 years old • Junior Ruby developer •

    Rails worshipper & • Mike’s best friend
  5. &

  6. & Any class you define is an instance of a

    class object called ‘Class'
  7. carrot class Cake class methods tasty? def tasty? @flavour ==

    “carrot” end Class methods edible? def edible? true end
  8. carrot class Cake class methods tasty? def tasty? @flavour ==

    “carrot” end Class methods edible? def edible? true end
  9. +

  10. "

  11. ,

  12. +

  13. "

  14. +

  15. :

  16. "

  17. =

  18. "

  19. "

  20. Budgeting Inc. A The codebase was a mess! •Lots of

    duplicate code •Inefficient development •Bugs and oversights
  21. +

  22. class CityInstance def self.construct(&block) city = new city.instance_eval(&block)
 city end

    
 attr_reader :taxes 
 
 def initialize
 @taxes = []
 end
 
 def tax(name)
 @taxes.push(name)
 end end

  23. class CityInstance def self.construct(&block) city = new city.instance_eval(&block)
 city end

    
 attr_reader :taxes 
 
 def initialize
 @taxes = []
 end
 
 def tax(name)
 @taxes.push(name)
 end end

  24. class CityInstance def self.construct(&block) city = new city.instance_eval(&block)
 city end

    
 attr_reader :taxes 
 
 def initialize
 @taxes = []
 end
 
 def tax(name)
 @taxes.push(name)
 end end

  25. class CityInstance def self.construct(&block) city = new city.instance_eval(&block)
 city end

    
 attr_reader :taxes 
 
 def initialize
 @taxes = []
 end
 
 def tax(name)
 @taxes.push(name)
 end end

  26. class CityInstance def self.construct(&block) city = new city.instance_eval(&block)
 city end

    
 attr_reader :taxes 
 
 def initialize
 @taxes = []
 end
 
 def tax(name)
 @taxes.push(name)
 end end

  27. class CityInstance def self.construct(&block) city = new city.instance_eval(&block)
 city end

    
 attr_reader :taxes 
 
 def initialize
 @taxes = []
 end
 
 def tax(name)
 @taxes.push(name)
 end end

  28. class CityInstance def self.construct(&block) city = new city.instance_eval(&block)
 city end

    
 attr_reader :taxes 
 
 def initialize
 @taxes = []
 end
 
 def tax(name)
 @taxes.push(name)
 end end

  29. class CityInstance def self.construct(&block) city = new city.instance_eval(&block)
 city end

    
 attr_reader :taxes 
 
 def initialize
 @taxes = []
 end
 
 def tax(name)
 @taxes.push(name)
 end end

  30. class CityInstance def self.construct(&block) city = new city.instance_eval(&block)
 city end

    
 attr_reader :taxes 
 
 def initialize
 @taxes = []
 end
 
 def tax(name)
 @taxes.push(name)
 end end

  31. class CityInstance def self.construct(&block) city = new city.instance_eval(&block)
 city end

    
 attr_reader :taxes 
 
 def initialize
 @taxes = []
 end
 
 def tax(name)
 @taxes.push(name)
 end end

  32. A The DSL allowed for quick and easy scaffolding of

    each new City subclass and any related classes.
  33. Budgeting Inc. A • Effortless scaffolding • Better maintainability •

    Easier customisation All common code was consolidated in one place!
  34. D

  35. F

  36. G

  37. carrot class Cake class methods tasty? def tasty? @flavour ==

    “carrot” end Cake singleton methods edible? def edible? true end
  38. &

  39. "

  40. G

  41. A

  42. "

  43. Due to being distraught at Jenny’s betrayal, Mike performed badly

    at the RIP interview… ジェニーの裏切りに動揺した結果、 マイクはRIPの⾯面接に失敗してしま う。
  44. Jenny is 3 months into an apprenticeship at the RIP.

    ジェニーはRIP社にて3ヶ⽉月⽬目の⾒見見習い 中。
  45. SOURCES FRIENDS OF DEE Ruby Under A Microscope Book by

    Pat Shaughnessy
 Ruby, Smalltalk and Class Variables Blog post by Pat Shaughnessy
 Ruby Tapas — Episodes 453, 454, and 456 Screencasts by Avdi Grimm Benefits of Writinng a DSL in Ruby Blog post by Gusto
 DslQandA Blog post by Martin Fowler Eigen What Now? Talk by Eliza de Jager Aaron Patterson Adam Cuppy Aly Blenkin Andy Croll Ana Carlos Avdi Grimm Ebi Jonathan Tsang Pat Shaughnessy Saron Yitbarek Tammer Saleh Nadia Odunayo, @nodunayo