Save 37% off PRO during our Black Friday Sale! »

Get a Whiff of This

Get a Whiff of This

A talk about code smells

66ad01cf37c098bfdb76906a490e018f?s=128

Sandi Metz

May 06, 2016
Tweet

Transcript

  1. May 2016 @sandimetz Sandi Metz Get a Whiff of This

    Sandi Metz
  2. @sandimetz May 2016 Kent Beck

  3. @sandimetz May 2016 Kent Beck Martin Fowler

  4. @sandimetz May 2016 Kent Beck Martin Fowler

  5. @sandimetz May 2016 Classic Smells

  6. @sandimetz May 2016 Classic Smells Alternative Classes w/ Different Interfaces

    Comments Data Class Data Clumps Divergent Change Duplicated Code Feature Envy Parallel Inheritance Hierarchies Primitive Obsession Refused Bequest Shotgun Surgery Speculative Generality Switch Statements Temporary Field Inappropriate Intimacy Incomplete Library Client Large Class Long Method Long Parameter List Message Chains Middle Man Lazy Class
  7. @sandimetz May 2016

  8. @sandimetz May 2016 Alternative Classes w/ Different Interfaces Comments Data

    Class Data Clumps Divergent Change Duplicated Code Feature Envy Parallel Inheritance Hierarchies Primitive Obsession Refused Bequest Shotgun Surgery Speculative Generality Switch Statements Temporary Field Classic Smells Inappropriate Intimacy Incomplete Library Client Large Class Long Method Long Parameter List Message Chains Middle Man Lazy Class
  9. @sandimetz May 2016 Alternative Classes w/ Different Interfaces Comments Data

    Class Data Clumps Divergent Change Duplicated Code Feature Envy Parallel Inheritance Hierarchies Primitive Obsession Refused Bequest Shotgun Surgery Speculative Generality Switch Statements Temporary Field Classic Smells Inappropriate Intimacy Incomplete Library Client Long Method Long Parameter List Message Chains Middle Man Lazy Class Large Class
  10. @sandimetz May 2016 Alternative Classes w/ Different Interfaces Data Class

    Data Clumps Divergent Change Duplicated Code Feature Envy Parallel Inheritance Hierarchies Primitive Obsession Refused Bequest Shotgun Surgery Speculative Generality Switch Statements Temporary Field Classic Smells Inappropriate Intimacy Long Method Long Parameter List Message Chains Middle Man Lazy Class Large Class
  11. @sandimetz May 2016 Divergent Change Parallel Inheritance Hierarchies Shotgun Surgery

    Alternative Classes w/ Different Interfaces Refused Bequest Switch Statements Temporary Field Feature Envy Inappropriate Intimacy Message Chains Middle Man Data Class Duplicated Code Speculative Generality Lazy Class Data Clumps Primitive Obsession Long Method Long Parameter List Large Class
  12. @sandimetz May 2016 Data Clumps Primitive Obsession Long Method Long

    Parameter List Large Class
  13. @sandimetz May 2016 Data Clumps Primitive Obsession Long Method Long

    Parameter List Large Class
  14. @sandimetz May 2016 Bloaters Data Clumps Primitive Obsession Long Method

    Long Parameter List Large Class
  15. @sandimetz May 2016 Alternative Classes w/ Different Interfaces Refused Bequest

    Switch Statements Temporary Field Divergent Change Parallel Inheritance Hierarchies Shotgun Surgery Feature Envy Inappropriate Intimacy Message Chains Middle Man Data Class Duplicated Code Speculative Generality Lazy Class Data Clumps Primitive Obsession Long Method Long Parameter List Large Class Bloaters
  16. @sandimetz May 2016 Alternative Classes w/ Different Interfaces Refused Bequest

    Switch Statements Temporary Field
  17. @sandimetz May 2016 Alternative Classes w/ Different Interfaces Refused Bequest

    Switch Statements Temporary Field
  18. @sandimetz May 2016 Alternative Classes w/ Different Interfaces Refused Bequest

    Switch Statements Temporary Field
  19. @sandimetz May 2016 Tool Abusers Alternative Classes w/ Different Interfaces

    Refused Bequest Switch Statements Temporary Field
  20. @sandimetz May 2016 Divergent Change Parallel Inheritance Hierarchies Shotgun Surgery

    Alternative Classes w/ Different Interfaces Refused Bequest Switch Statements Temporary Field Feature Envy Inappropriate Intimacy Message Chains Middle Man Data Class Duplicated Code Speculative Generality Lazy Class Data Clumps Primitive Obsession Long Method Long Parameter List Large Class Bloaters Abusers Divergent Change Parallel Inheritance Hierarchies Shotgun Surgery
  21. @sandimetz May 2016 Divergent Change Parallel Inheritance Hierarchies Shotgun Surgery

    Divergent Change Parallel Inheritance Hierarchies Shotgun Surgery
  22. @sandimetz May 2016 Divergent Change Parallel Inheritance Hierarchies Shotgun Surgery

  23. @sandimetz May 2016 Divergent Change Parallel Inheritance Hierarchies Shotgun Surgery

  24. @sandimetz May 2016 Change Preventers Divergent Change Parallel Inheritance Hierarchies

    Shotgun Surgery
  25. @sandimetz May 2016 Data Class Duplicated Code Speculative Generality Lazy

    Class Feature Envy Inappropriate Intimacy Message Chains Middle Man Divergent Change Parallel Inheritance Hierarchies Shotgun Surgery Alternative Classes w/ Different Interfaces Refused Bequest Switch Statements Temporary Field Data Clumps Primitive Obsession Long Method Long Parameter List Large Class Bloaters Abusers Preventers
  26. @sandimetz May 2016 Data Class Duplicated Code Speculative Generality Lazy

    Class
  27. @sandimetz May 2016 Data Class Duplicated Code Speculative Generality Lazy

    Class
  28. @sandimetz May 2016 Data Class Duplicated Code Speculative Generality Lazy

    Class
  29. @sandimetz May 2016 Dispensables Data Class Duplicated Code Speculative Generality

    Lazy Class
  30. @sandimetz May 2016 Feature Envy Inappropriate Intimacy Message Chains Middle

    Man Data Class Duplicated Code Speculative Generality Lazy Class Divergent Change Parallel Inheritance Hierarchies Shotgun Surgery Alternative Classes w/ Different Interfaces Refused Bequest Switch Statements Temporary Field Data Clumps Primitive Obsession Long Method Long Parameter List Large Class Bloaters Abusers Preventers Dispensables
  31. @sandimetz May 2016 Feature Envy Inappropriate Intimacy Message Chains Middle

    Man
  32. @sandimetz May 2016 Feature Envy Inappropriate Intimacy Message Chains Middle

    Man
  33. @sandimetz May 2016 Feature Envy Inappropriate Intimacy Message Chains Middle

    Man
  34. @sandimetz May 2016 Couplers Feature Envy Inappropriate Intimacy Message Chains

    Middle Man
  35. @sandimetz May 2016 Feature Envy Inappropriate Intimacy Message Chains Middle

    Man Data Class Duplicated Code Speculative Generality Lazy Class Divergent Change Parallel Inheritance Hierarchies Shotgun Surgery Alternative Classes w/ Different Interfaces Refused Bequest Switch Statements Temporary Field Data Clumps Primitive Obsession Long Method Long Parameter List Large Class Bloaters Abusers Preventers Dispensables Couplers
  36. @sandimetz May 2016 Refactoring

  37. @sandimetz May 2016 Refactoring Recipe

  38. @sandimetz May 2016 Fowler 149: Extract Class

  39. @sandimetz May 2016 Refactoring Recipe

  40. @sandimetz May 2016 Code Smell Curative Refactoring Recipe

  41. @sandimetz May 2016 http://www.industriallogic.com/wp-content/uploads/2005/09/smellstorefactorings.pdf

  42. @sandimetz May 2016 http://www.industriallogic.com/wp-content/uploads/2005/09/smellstorefactorings.pdf

  43. @sandimetz May 2016

  44. @sandimetz May 2016 1

  45. @sandimetz May 2016 class Sale < Persistence end

  46. @sandimetz May 2016 class Sale < Persistence end class Foo

    def sales_total(params) Sale.where(date: (Date.parse(params[:starting]))..(Date.parse(params[:ending]))).sum("cost") end end
  47. @sandimetz May 2016 class Sale < Persistence end class Foo

    def sales_total(params) Sale.where(date: (Date.parse(params[:starting]))..(Date.parse(params[:ending]))).sum("cost") end end
  48. @sandimetz May 2016 class Sale < Persistence end class Foo

    def sales_total(params) Sale.where(date: (Date.parse(params[:starting]))..(Date.parse(params[:ending]))).sum("cost") end end
  49. @sandimetz May 2016 class Sale < Persistence end class Foo

    def sales_total(params) Sale.where(date: (Date.parse(params[:starting]))..(Date.parse(params[:ending]))).sum("cost") end end
  50. @sandimetz May 2016 class Sale < Persistence end class Foo

    def sales_total(params) Sale.where(date: (Date.parse(params[:starting]))..(Date.parse(params[:ending]))).sum("cost") end end
  51. @sandimetz May 2016 class Sale < Persistence end class Foo

    def sales_total(params) Sale.where(date: (Date.parse(params[:starting]))..(Date.parse(params[:ending]))).sum("cost") end end
  52. @sandimetz May 2016 class Sale < Persistence end class Foo

    def sales_total(params) Sale.where(date: (Date.parse(params[:starting]))..(Date.parse(params[:ending]))).sum("cost") end end
  53. @sandimetz May 2016 class Sale < Persistence end class Foo

    def sales_total(params) Sale.where(date: (Date.parse(params[:starting]))..(Date.parse(params[:ending]))).sum("cost") end end
  54. @sandimetz May 2016 class Sale < Persistence end class Foo

    def sales_total(params) Sale.where(date: (Date.parse(params[:starting]))..(Date.parse(params[:ending]))).sum("cost") end end class Bar def weekly_sales_total(params) start_date = (Date.parse(params[:starting])) end_date = start_date + 6 Sale.where(date: (start_date..end_date)).sum("cost") end end
  55. @sandimetz May 2016 class Sale < Persistence end class Foo

    def sales_total(params) Sale.where(date: (Date.parse(params[:starting]))..(Date.parse(params[:ending]))).sum("cost") end end class Bar def weekly_sales_total(params) start_date = (Date.parse(params[:starting])) end_date = start_date + 6 Sale.where(date: (start_date..end_date)).sum("cost") end end
  56. @sandimetz May 2016 class Sale < Persistence end class Foo

    def sales_total(params) Sale.where(date: (Date.parse(params[:starting]))..(Date.parse(params[:ending]))).sum("cost") end end class Bar def weekly_sales_total(params) start_date = (Date.parse(params[:starting])) end_date = start_date + 6 Sale.where(date: (start_date..end_date)).sum("cost") end end
  57. @sandimetz May 2016 class Sale < Persistence end class Foo

    def sales_total(params) Sale.where(date: (Date.parse(params[:starting]))..(Date.parse(params[:ending]))).sum("cost") end end class Bar def weekly_sales_total(params) start_date = (Date.parse(params[:starting])) end_date = start_date + 6 Sale.where(date: (start_date..end_date)).sum("cost") end end
  58. @sandimetz May 2016 class Sale < Persistence end class Foo

    def sales_total(params) Sale.where(date: (Date.parse(params[:starting]))..(Date.parse(params[:ending]))).sum("cost") end end class Bar def weekly_sales_total(params) start_date = (Date.parse(params[:starting])) end_date = start_date + 6 Sale.where(date: (start_date..end_date)).sum("cost") end end
  59. @sandimetz May 2016 class Sale < Persistence end class Foo

    def sales_total(params) Sale.where(date: (Date.parse(params[:starting]))..(Date.parse(params[:ending]))).sum("cost") end end class Bar def weekly_sales_total(params) start_date = (Date.parse(params[:starting])) end_date = start_date + 6 Sale.where(date: (start_date..end_date)).sum("cost") end end
  60. @sandimetz May 2016 class Sale < Persistence end class Foo

    def sales_total(params) Sale.where(date: (Date.parse(params[:starting]))..(Date.parse(params[:ending]))).sum("cost") end end class Bar def weekly_sales_total(params) start_date = (Date.parse(params[:starting])) end_date = start_date + 6 Sale.where(date: (start_date..end_date)).sum("cost") end end
  61. @sandimetz May 2016 class Sale < Persistence end class Foo

    def sales_total(params) Sale.where(date: (Date.parse(params[:starting]))..(Date.parse(params[:ending]))).sum("cost") end end class Bar def weekly_sales_total(params) start_date = (Date.parse(params[:starting])) end_date = start_date + 6 Sale.where(date: (start_date..end_date)).sum("cost") end end
  62. @sandimetz May 2016 class Sale < Persistence end class Foo

    def sales_total(params) Sale.where(date: (Date.parse(params[:starting]))..(Date.parse(params[:ending]))).sum("cost") end end class Bar def weekly_sales_total(params) start_date = (Date.parse(params[:starting])) end_date = start_date + 6 Sale.where(date: (start_date..end_date)).sum("cost") end end
  63. @sandimetz May 2016 class Sale < Persistence end class Foo

    def sales_total(params) Sale.where(date: (Date.parse(params[:starting]))..(Date.parse(params[:ending]))).sum("cost") end end class Bar def weekly_sales_total(params) start_date = (Date.parse(params[:starting])) end_date = start_date + 6 Sale.where(date: (start_date..end_date)).sum("cost") end end
  64. @sandimetz May 2016 class Sale < Persistence end class Expense

    < Persistence end class Foo def sales_total(params) Sale.where(date: (Date.parse(params[:starting]))..(Date.parse(params[:ending]))).sum("cost") end end class Bar def weekly_sales_total(params) start_date = (Date.parse(params[:starting])) end_date = start_date + 6 Sale.where(date: (start_date..end_date)).sum("cost") end end
  65. @sandimetz May 2016 class Sale < Persistence end class Expense

    < Persistence end class Foo def sales_total(params) Sale.where(date: (Date.parse(params[:starting]))..(Date.parse(params[:ending]))).sum("cost") end end class Bar def weekly_sales_total(params) start_date = (Date.parse(params[:starting])) end_date = start_date + 6 Sale.where(date: (start_date..end_date)).sum("cost") end end class Baz def expense_total(params) Expense.where(date: (Date.parse(params[:starting]))..(Date.parse(params[:ending]))).sum("cost") end end
  66. @sandimetz May 2016 class Sale < Persistence end class Expense

    < Persistence end class Foo def sales_total(params) Sale.where(date: (Date.parse(params[:starting]))..(Date.parse(params[:ending]))).sum("cost") end end class Bar def weekly_sales_total(params) start_date = (Date.parse(params[:starting])) end_date = start_date + 6 Sale.where(date: (start_date..end_date)).sum("cost") end end class Baz def expense_total(params) Expense.where(date: (Date.parse(params[:starting]))..(Date.parse(params[:ending]))).sum("cost") end end
  67. @sandimetz May 2016 class Sale < Persistence end class Expense

    < Persistence end class Foo def sales_total(params) Sale.where(date: (Date.parse(params[:starting]))..(Date.parse(params[:ending]))).sum("cost") end end class Bar def weekly_sales_total(params) start_date = (Date.parse(params[:starting])) end_date = start_date + 6 Sale.where(date: (start_date..end_date)).sum("cost") end end class Baz def expense_total(params) Expense.where(date: (Date.parse(params[:starting]))..(Date.parse(params[:ending]))).sum("cost") end end
  68. @sandimetz May 2016 class Sale < Persistence end class Expense

    < Persistence end class Foo def sales_total(params) Sale.where(date: (Date.parse(params[:starting]))..(Date.parse(params[:ending]))).sum("cost") end end class Bar def weekly_sales_total(params) start_date = (Date.parse(params[:starting])) end_date = start_date + 6 Sale.where(date: (start_date..end_date)).sum("cost") end end class Baz def expense_total(params) Expense.where(date: (Date.parse(params[:starting]))..(Date.parse(params[:ending]))).sum("cost") end end
  69. @sandimetz May 2016 class Sale < Persistence end class Expense

    < Persistence end class Foo def sales_total(params) Sale.where(date: (Date.parse(params[:starting]))..(Date.parse(params[:ending]))).sum("cost") end end class Bar def weekly_sales_total(params) start_date = (Date.parse(params[:starting])) end_date = start_date + 6 Sale.where(date: (start_date..end_date)).sum("cost") end end class Baz def expense_total(params) Expense.where(date: (Date.parse(params[:starting]))..(Date.parse(params[:ending]))).sum("cost") end end
  70. @sandimetz May 2016 class Sale < Persistence end class Expense

    < Persistence end class Foo def sales_total(params) Sale.where(date: (Date.parse(params[:starting]))..(Date.parse(params[:ending]))).sum("cost") end end class Bar def weekly_sales_total(params) start_date = (Date.parse(params[:starting])) end_date = start_date + 6 Sale.where(date: (start_date..end_date)).sum("cost") end end class Baz def expense_total(params) Expense.where(date: (Date.parse(params[:starting]))..(Date.parse(params[:ending]))).sum("cost") end end
  71. @sandimetz May 2016 class Sale < Persistence end class Expense

    < Persistence end class Foo def sales_total(params) Sale.where(date: (Date.parse(params[:starting]))..(Date.parse(params[:ending]))).sum("cost") end end class Bar def weekly_sales_total(params) start_date = (Date.parse(params[:starting])) end_date = start_date + 6 Sale.where(date: (start_date..end_date)).sum("cost") end end class Baz def expense_total(params) Expense.where(date: (Date.parse(params[:starting]))..(Date.parse(params[:ending]))).sum("cost") end end Kaboom
  72. @sandimetz May 2016 class Sale < Persistence end class Expense

    < Persistence end class Foo def sales_total(params) Sale.where(date: (Date.parse(params[:starting]))..(Date.parse(params[:ending]))).sum("cost") end end class Bar def weekly_sales_total(params) start_date = (Date.parse(params[:starting])) end_date = start_date + 6 Sale.where(date: (start_date..end_date)).sum("cost") end end class Baz def expense_total(params) Expense.where(date: (Date.parse(params[:starting]))..(Date.parse(params[:ending]))).sum("cost") end end
  73. @sandimetz May 2016 class Sale < Persistence end class Expense

    < Persistence end class Foo def sales_total(params) Sale.where(date: (Date.parse(params[:starting]))..(Date.parse(params[:ending]))).sum("cost") end end class Bar def weekly_sales_total(params) start_date = (Date.parse(params[:starting])) end_date = start_date + 6 Sale.where(date: (start_date..end_date)).sum("cost") end end class Baz def expense_total(params) start_date = (Date.parse(params[:starting])) rescue Date.today end_date = (Date.parse(params[:ending])) rescue start_date Expense.where(date: (Date.parse(params[:starting]))..(Date.parse(params[:ending]))).sum("cost") end end
  74. @sandimetz May 2016 class Sale < Persistence end class Expense

    < Persistence end class Foo def sales_total(params) Sale.where(date: (Date.parse(params[:starting]))..(Date.parse(params[:ending]))).sum("cost") end end class Bar def weekly_sales_total(params) start_date = (Date.parse(params[:starting])) end_date = start_date + 6 Sale.where(date: (start_date..end_date)).sum("cost") end end class Baz def expense_total(params) start_date = (Date.parse(params[:starting])) rescue Date.today end_date = (Date.parse(params[:ending])) rescue start_date Expense.where(date: (Date.parse(params[:starting]))..(Date.parse(params[:ending]))).sum("cost") end end
  75. @sandimetz May 2016 class Sale < Persistence end class Expense

    < Persistence end class Foo def sales_total(params) Sale.where(date: (Date.parse(params[:starting]))..(Date.parse(params[:ending]))).sum("cost") end end class Bar def weekly_sales_total(params) start_date = (Date.parse(params[:starting])) end_date = start_date + 6 Sale.where(date: (start_date..end_date)).sum("cost") end end class Baz def expense_total(params) start_date = (Date.parse(params[:starting])) rescue Date.today end_date = (Date.parse(params[:ending])) rescue start_date Expense.where(date: (Date.parse(params[:starting]))..(Date.parse(params[:ending]))).sum("cost") end end
  76. @sandimetz May 2016 class Sale < Persistence end class Expense

    < Persistence end class Foo def sales_total(params) Sale.where(date: (Date.parse(params[:starting]))..(Date.parse(params[:ending]))).sum("cost") end end class Bar def weekly_sales_total(params) start_date = (Date.parse(params[:starting])) end_date = start_date + 6 Sale.where(date: (start_date..end_date)).sum("cost") end end class Baz def expense_total(params) start_date = (Date.parse(params[:starting])) rescue Date.today end_date = (Date.parse(params[:ending])) rescue start_date Expense.where(date: (Date.parse(params[:starting]))..(Date.parse(params[:ending]))).sum("cost") end end
  77. @sandimetz May 2016 class Sale < Persistence end class Expense

    < Persistence end class Foo def sales_total(params) Sale.where(date: (Date.parse(params[:starting]))..(Date.parse(params[:ending]))).sum("cost") end end class Bar def weekly_sales_total(params) start_date = (Date.parse(params[:starting])) end_date = start_date + 6 Sale.where(date: (start_date..end_date)).sum("cost") end end class Baz def expense_total(params) start_date = (Date.parse(params[:starting])) rescue Date.today end_date = (Date.parse(params[:ending])) rescue start_date Expense.where(date: (Date.parse(params[:starting]))..(Date.parse(params[:ending]))).sum("cost") end end
  78. @sandimetz May 2016 class Sale < Persistence end class Expense

    < Persistence end class Foo def sales_total(params) Sale.where(date: (Date.parse(params[:starting]))..(Date.parse(params[:ending]))).sum("cost") end end class Bar def weekly_sales_total(params) start_date = (Date.parse(params[:starting])) end_date = start_date + 6 Sale.where(date: (start_date..end_date)).sum("cost") end end class Baz def expense_total(params) start_date = (Date.parse(params[:starting])) rescue Date.today end_date = (Date.parse(params[:ending])) rescue start_date Expense.where(date: (Date.parse(params[:starting]))..(Date.parse(params[:ending]))).sum("cost") end end
  79. @sandimetz May 2016 class Sale < Persistence end class Expense

    < Persistence end class Foo def sales_total(params) Sale.where(date: (Date.parse(params[:starting]))..(Date.parse(params[:ending]))).sum("cost") end end class Bar def weekly_sales_total(params) start_date = (Date.parse(params[:starting])) end_date = start_date + 6 Sale.where(date: (start_date..end_date)).sum("cost") end end class Baz def expense_total(params) start_date = (Date.parse(params[:starting])) rescue Date.today end_date = (Date.parse(params[:ending])) rescue start_date Expense.where(date: (Date.parse(params[:starting]))..(Date.parse(params[:ending]))).sum("cost") end end
  80. @sandimetz May 2016 class Sale < Persistence end class Expense

    < Persistence end class Foo def sales_total(params) Sale.where(date: (Date.parse(params[:starting]))..(Date.parse(params[:ending]))).sum("cost") end end class Bar def weekly_sales_total(params) start_date = (Date.parse(params[:starting])) end_date = start_date + 6 Sale.where(date: (start_date..end_date)).sum("cost") end end class Baz def expense_total(params) start_date = (Date.parse(params[:starting])) rescue Date.today end_date = (Date.parse(params[:ending])) rescue start_date Expense.where(date: (Date.parse(params[:starting]))..(Date.parse(params[:ending]))).sum("cost") end end
  81. @sandimetz May 2016 class Sale < Persistence end class Expense

    < Persistence end class Foo def sales_total(params) Sale.where(date: (Date.parse(params[:starting]))..(Date.parse(params[:ending]))).sum("cost") end end class Bar def weekly_sales_total(params) start_date = (Date.parse(params[:starting])) end_date = start_date + 6 Sale.where(date: (start_date..end_date)).sum("cost") end end class Baz def expense_total(params) start_date = (Date.parse(params[:starting])) rescue Date.today end_date = (Date.parse(params[:ending])) rescue start_date Expense.where(date: (Date.parse(params[:starting]))..(Date.parse(params[:ending]))).sum("cost") end end
  82. @sandimetz May 2016 class Sale < Persistence end class Expense

    < Persistence end class Foo def sales_total(params) Sale.where(date: (Date.parse(params[:starting]))..(Date.parse(params[:ending]))).sum("cost") end end class Bar def weekly_sales_total(params) start_date = (Date.parse(params[:starting])) end_date = start_date + 6 Sale.where(date: (start_date..end_date)).sum("cost") end end class Baz def expense_total(params) start_date = (Date.parse(params[:starting])) rescue Date.today end_date = (Date.parse(params[:ending])) rescue start_date Expense.where(date: (Date.parse(params[:starting]))..(Date.parse(params[:ending]))).sum("cost") end end
  83. @sandimetz May 2016 class Sale < Persistence end class Expense

    < Persistence end class Foo def sales_total(params) Sale.where(date: (Date.parse(params[:starting]))..(Date.parse(params[:ending]))).sum("cost") end end class Bar def weekly_sales_total(params) start_date = (Date.parse(params[:starting])) end_date = start_date + 6 Sale.where(date: (start_date..end_date)).sum("cost") end end class Baz def expense_total(params) start_date = (Date.parse(params[:starting])) rescue Date.today end_date = (Date.parse(params[:ending])) rescue start_date Expense.where(date: (Date.parse(params[:starting]))..(Date.parse(params[:ending]))).sum("cost") end end class Larry def sales_total(params) Sale.where(date: (Date.parse(params[:starting]))..(Date.parse(params[:ending]))).sum("cost") end end class Curly def weekly_sales_total(params) start_date = (Date.parse(params[:starting])) end_date = start_date + 6 Sale.where(date: (start_date..end_date)).sum("cost") end end class Mo def expense_total(params) start_date = (Date.parse(params[:starting])) rescue Date.today end_date = (Date.parse(params[:ending])) rescue start_date Expense.where(date: (Date.parse(params[:starting]))..(Date.parse(params[:ending]))).sum("cost") end end
  84. @sandimetz May 2016 class Sale < Persistence end class Expense

    < Persistence end class Foo def sales_total(params) Sale.where(date: (Date.parse(params[:starting]))..(Date.parse(params[:ending]))).sum("cost") end end class Bar def weekly_sales_total(params) start_date = (Date.parse(params[:starting])) end_date = start_date + 6 Sale.where(date: (start_date..end_date)).sum("cost") end end class Baz def expense_total(params) start_date = (Date.parse(params[:starting])) rescue Date.today end_date = (Date.parse(params[:ending])) rescue start_date Expense.where(date: (Date.parse(params[:starting]))..(Date.parse(params[:ending]))).sum("cost") end end class Larry def sales_total(params) Sale.where(date: (Date.parse(params[:starting]))..(Date.parse(params[:ending]))).sum("cost") end end class Curly def weekly_sales_total(params) start_date = (Date.parse(params[:starting])) end_date = start_date + 6 Sale.where(date: (start_date..end_date)).sum("cost") end end class Mo def expense_total(params) start_date = (Date.parse(params[:starting])) rescue Date.today end_date = (Date.parse(params[:ending])) rescue start_date Expense.where(date: (Date.parse(params[:starting]))..(Date.parse(params[:ending]))).sum("cost") end end class Fee def sales_total(params) Sale.where(date: (Date.parse(params[:starting]))..(Date.parse(params[:ending]))).sum("cost") end end class Fi def weekly_sales_total(params) start_date = (Date.parse(params[:starting])) end_date = start_date + 6 Sale.where(date: (start_date..end_date)).sum("cost") end end class Foe def expense_total(params) start_date = (Date.parse(params[:starting])) rescue Date.today end_date = (Date.parse(params[:ending])) rescue start_date Expense.where(date: (Date.parse(params[:starting]))..(Date.parse(params[:ending]))).sum("cost") end end
  85. @sandimetz May 2016 class Sale < Persistence end class Expense

    < Persistence end class Foo def sales_total(params) Sale.where(date: (Date.parse(params[:starting]))..(Date.parse(params[:ending]))).sum("cost") end end class Bar def weekly_sales_total(params) start_date = (Date.parse(params[:starting])) end_date = start_date + 6 Sale.where(date: (start_date..end_date)).sum("cost") end end class Baz def expense_total(params) start_date = (Date.parse(params[:starting])) rescue Date.today end_date = (Date.parse(params[:ending])) rescue start_date Expense.where(date: (Date.parse(params[:starting]))..(Date.parse(params[:ending]))).sum("cost") end end class Larry def sales_total(params) Sale.where(date: (Date.parse(params[:starting]))..(Date.parse(params[:ending]))).sum("cost") end end class Curly def weekly_sales_total(params) start_date = (Date.parse(params[:starting])) end_date = start_date + 6 Sale.where(date: (start_date..end_date)).sum("cost") end end class Mo def expense_total(params) start_date = (Date.parse(params[:starting])) rescue Date.today end_date = (Date.parse(params[:ending])) rescue start_date Expense.where(date: (Date.parse(params[:starting]))..(Date.parse(params[:ending]))).sum("cost") end end class Fee def sales_total(params) Sale.where(date: (Date.parse(params[:starting]))..(Date.parse(params[:ending]))).sum("cost") end end class Fi def weekly_sales_total(params) start_date = (Date.parse(params[:starting])) end_date = start_date + 6 Sale.where(date: (start_date..end_date)).sum("cost") end end class Foe def expense_total(params) start_date = (Date.parse(params[:starting])) rescue Date.today end_date = (Date.parse(params[:ending])) rescue start_date Expense.where(date: (Date.parse(params[:starting]))..(Date.parse(params[:ending]))).sum("cost") end end
  86. @sandimetz May 2016

  87. @sandimetz May 2016 2 Data Clump | Extract Class

  88. @sandimetz May 2016 class Sale < Persistence end class Expense

    < Persistence end class Foo def sales_total(params) Sale.where(date: (Date.parse(params[:starting]))..(Date.parse(params[:ending]))).sum("cost") end end class Bar def weekly_sales_total(params) start_date = (Date.parse(params[:starting])) end_date = start_date + 6 Sale.where(date: (start_date..end_date)).sum("cost") end end class Baz def expense_total(params) start_date = (Date.parse(params[:starting])) rescue Date.today end_date = (Date.parse(params[:ending])) rescue start_date Expense.where(date: (Date.parse(params[:starting]))..(Date.parse(params[:ending]))).sum("cost") end end
  89. @sandimetz May 2016 class Sale < Persistence end class Expense

    < Persistence end class Foo def sales_total(params) Sale.where(date: (Date.parse(params[:starting]))..(Date.parse(params[:ending]))).sum("cost") end end class Bar def weekly_sales_total(params) start_date = (Date.parse(params[:starting])) end_date = start_date + 6 Sale.where(date: (start_date..end_date)).sum("cost") end end class Baz def expense_total(params) start_date = (Date.parse(params[:starting])) rescue Date.today end_date = (Date.parse(params[:ending])) rescue start_date Expense.where(date: (Date.parse(params[:starting]))..(Date.parse(params[:ending]))).sum("cost") end end
  90. @sandimetz May 2016 class DateRange attr_reader :starting, :ending def initialize(starting:,

    ending: nil) @starting = Date.parse(starting) rescue Date.today @ending = Date.parse(ending) rescue @starting end def range starting..ending end def week_range starting..(starting + 6) end end
  91. @sandimetz May 2016 class DateRange attr_reader :starting, :ending def initialize(starting:,

    ending: nil) @starting = Date.parse(starting) rescue Date.today @ending = Date.parse(ending) rescue @starting end def range starting..ending end def week_range starting..(starting + 6) end end
  92. @sandimetz May 2016 class DateRange attr_reader :starting, :ending def initialize(starting:,

    ending: nil) @starting = Date.parse(starting) rescue Date.today @ending = Date.parse(ending) rescue @starting end def range starting..ending end def week_range starting..(starting + 6) end end
  93. @sandimetz May 2016 class DateRange attr_reader :starting, :ending def initialize(starting:,

    ending: nil) @starting = Date.parse(starting) rescue Date.today @ending = Date.parse(ending) rescue @starting end def range starting..ending end def week_range starting..(starting + 6) end end
  94. @sandimetz May 2016 class DateRange attr_reader :starting, :ending def initialize(starting:,

    ending: nil) @starting = Date.parse(starting) rescue Date.today @ending = Date.parse(ending) rescue @starting end def range starting..ending end def week_range starting..(starting + 6) end end
  95. @sandimetz May 2016 class DateRange attr_reader :starting, :ending def initialize(starting:,

    ending: nil) @starting = Date.parse(starting) rescue Date.today @ending = Date.parse(ending) rescue @starting end def range starting..ending end def week_range starting..(starting + 6) end end
  96. @sandimetz May 2016 class DateRange attr_reader :starting, :ending def initialize(starting:,

    ending: nil) @starting = Date.parse(starting) rescue Date.today @ending = Date.parse(ending) rescue @starting end def range starting..ending end def week_range starting..(starting + 6) end end
  97. @sandimetz May 2016 class DateRange attr_reader :starting, :ending def initialize(starting:,

    ending: nil) @starting = Date.parse(starting) rescue Date.today @ending = Date.parse(ending) rescue @starting end def range starting..ending end def week_range starting..(starting + 6) end end
  98. @sandimetz May 2016 class DateRange attr_reader :starting, :ending def initialize(starting:,

    ending: nil) @starting = Date.parse(starting) rescue Date.today @ending = Date.parse(ending) rescue @starting end def range starting..ending end def week_range starting..(starting + 6) end end class Foo def sales_total(params) Sale.where(date: (Date.parse(params[:starting]))..(Date.parse(params[:ending]))).sum("cost") end end
  99. @sandimetz May 2016 class DateRange attr_reader :starting, :ending def initialize(starting:,

    ending: nil) @starting = Date.parse(starting) rescue Date.today @ending = Date.parse(ending) rescue @starting end def range starting..ending end def week_range starting..(starting + 6) end end class Foo def sales_total(params) Sale.where(date: (Date.parse(params[:starting]))..(Date.parse(params[:ending]))).sum("cost") end end
  100. @sandimetz May 2016 class DateRange attr_reader :starting, :ending def initialize(starting:,

    ending: nil) @starting = Date.parse(starting) rescue Date.today @ending = Date.parse(ending) rescue @starting end def range starting..ending end def week_range starting..(starting + 6) end end class Foo def sales_total(params) range = DateRange.new(starting: params[:starting], ending: params[:ending]).range Sale.where(date: (Date.parse(params[:starting]))..(Date.parse(params[:ending]))).sum("cost") end end
  101. @sandimetz May 2016 class DateRange attr_reader :starting, :ending def initialize(starting:,

    ending: nil) @starting = Date.parse(starting) rescue Date.today @ending = Date.parse(ending) rescue @starting end def range starting..ending end def week_range starting..(starting + 6) end end class Foo def sales_total(params) range = DateRange.new(starting: params[:starting], ending: params[:ending]).range Sale.where(date: (Date.parse(params[:starting]))..(Date.parse(params[:ending]))).sum("cost") end end
  102. @sandimetz May 2016 class DateRange attr_reader :starting, :ending def initialize(starting:,

    ending: nil) @starting = Date.parse(starting) rescue Date.today @ending = Date.parse(ending) rescue @starting end def range starting..ending end def week_range starting..(starting + 6) end end class Foo def sales_total(params) range = DateRange.new(starting: params[:starting], ending: params[:ending]).range Sale.where(date: range).sum("cost") end end
  103. @sandimetz May 2016 class DateRange attr_reader :starting, :ending def initialize(starting:,

    ending: nil) @starting = Date.parse(starting) rescue Date.today @ending = Date.parse(ending) rescue @starting end def range starting..ending end def week_range starting..(starting + 6) end end
  104. @sandimetz May 2016 class DateRange attr_reader :starting, :ending def initialize(starting:,

    ending: nil) @starting = Date.parse(starting) rescue Date.today @ending = Date.parse(ending) rescue @starting end def range starting..ending end def week_range starting..(starting + 6) end end class Bar def weekly_sales_total(params) start_date = (Date.parse(params[:starting])) end_date = start_date + 6 Sale.where(date: (start_date..end_date)).sum("cost") end end
  105. @sandimetz May 2016 class DateRange attr_reader :starting, :ending def initialize(starting:,

    ending: nil) @starting = Date.parse(starting) rescue Date.today @ending = Date.parse(ending) rescue @starting end def range starting..ending end def week_range starting..(starting + 6) end end class Bar def weekly_sales_total(params) Sale.where(date: (start_date..end_date)).sum("cost") end end
  106. @sandimetz May 2016 class DateRange attr_reader :starting, :ending def initialize(starting:,

    ending: nil) @starting = Date.parse(starting) rescue Date.today @ending = Date.parse(ending) rescue @starting end def range starting..ending end def week_range starting..(starting + 6) end end class Bar def weekly_sales_total(params) range = DateRange.new(starting: params[:starting]).week_range Sale.where(date: (start_date..end_date)).sum("cost") end end
  107. @sandimetz May 2016 class DateRange attr_reader :starting, :ending def initialize(starting:,

    ending: nil) @starting = Date.parse(starting) rescue Date.today @ending = Date.parse(ending) rescue @starting end def range starting..ending end def week_range starting..(starting + 6) end end class Bar def weekly_sales_total(params) range = DateRange.new(starting: params[:starting]).week_range Sale.where(date: range).sum("cost") end end
  108. @sandimetz May 2016 class DateRange attr_reader :starting, :ending def initialize(starting:,

    ending: nil) @starting = Date.parse(starting) rescue Date.today @ending = Date.parse(ending) rescue @starting end def range starting..ending end def week_range starting..(starting + 6) end end class Bar def weekly_sales_total(params) range = DateRange.new(starting: params[:starting]).week_range Sale.where(date: range).sum("cost") end end
  109. @sandimetz May 2016 class DateRange attr_reader :starting, :ending def initialize(starting:,

    ending: nil) @starting = Date.parse(starting) rescue Date.today @ending = Date.parse(ending) rescue @starting end def range starting..ending end def week_range starting..(starting + 6) end end
  110. @sandimetz May 2016 class DateRange attr_reader :starting, :ending def initialize(starting:,

    ending: nil) @starting = Date.parse(starting) rescue Date.today @ending = Date.parse(ending) rescue @starting end def range starting..ending end def week_range starting..(starting + 6) end end class Baz def expense_total(params) start_date = (Date.parse(params[:starting])) rescue Date.today end_date = (Date.parse(params[:ending])) rescue start_date Expense.where(date: (Date.parse(params[:starting]))..(Date.parse(params[:ending]))).sum("cost") end end
  111. @sandimetz May 2016 class DateRange attr_reader :starting, :ending def initialize(starting:,

    ending: nil) @starting = Date.parse(starting) rescue Date.today @ending = Date.parse(ending) rescue @starting end def range starting..ending end def week_range starting..(starting + 6) end end class Baz def expense_total(params) Expense.where(date: (Date.parse(params[:starting]))..(Date.parse(params[:ending]))).sum("cost") end end
  112. @sandimetz May 2016 class DateRange attr_reader :starting, :ending def initialize(starting:,

    ending: nil) @starting = Date.parse(starting) rescue Date.today @ending = Date.parse(ending) rescue @starting end def range starting..ending end def week_range starting..(starting + 6) end end class Baz def expense_total(params) range = DateRange.new(starting: params[:starting], ending: params[:ending]).range Expense.where(date: (Date.parse(params[:starting]))..(Date.parse(params[:ending]))).sum("cost") end end
  113. @sandimetz May 2016 class DateRange attr_reader :starting, :ending def initialize(starting:,

    ending: nil) @starting = Date.parse(starting) rescue Date.today @ending = Date.parse(ending) rescue @starting end def range starting..ending end def week_range starting..(starting + 6) end end class Baz def expense_total(params) range = DateRange.new(starting: params[:starting], ending: params[:ending]).range Expense.where(date: range).sum("cost") end end
  114. @sandimetz May 2016 class DateRange attr_reader :starting, :ending def initialize(starting:,

    ending: nil) @starting = Date.parse(starting) rescue Date.today @ending = Date.parse(ending) rescue @starting end def range starting..ending end def week_range starting..(starting + 6) end end class Baz def expense_total(params) range = DateRange.new(starting: params[:starting], ending: params[:ending]).range Expense.where(date: range).sum("cost") end end
  115. @sandimetz May 2016 class Foo def sales_total(params) range = DateRange.new(starting:

    params[:starting], ending: params[:ending]).range Sale.where(date: range).sum("cost") end end class Bar def weekly_sales_total(params) range = DateRange.new(starting: params[:starting]).week_range Sale.where(date: range).sum("cost") end end class Baz def expense_total(params) range = DateRange.new(starting: params[:starting], ending: params[:ending]).range Expense.where(date: range).sum("cost") end end
  116. @sandimetz May 2016 class Foo def sales_total(params) range = DateRange.new(starting:

    params[:starting], ending: params[:ending]).range Sale.where(date: range).sum("cost") end end class Bar def weekly_sales_total(params) range = DateRange.new(starting: params[:starting]).week_range Sale.where(date: range).sum("cost") end end class Baz def expense_total(params) range = DateRange.new(starting: params[:starting], ending: params[:ending]).range Expense.where(date: range).sum("cost") end end
  117. @sandimetz May 2016 class Foo def sales_total(params) range = DateRange.new(starting:

    params[:starting], ending: params[:ending]).range Sale.where(date: range).sum("cost") end end class Bar def weekly_sales_total(params) range = DateRange.new(starting: params[:starting]).week_range Sale.where(date: range).sum("cost") end end class Baz def expense_total(params) range = DateRange.new(starting: params[:starting], ending: params[:ending]).range Expense.where(date: range).sum("cost") end end Data Clump | Extract Class
  118. @sandimetz May 2016 3 Message Chain | Hide Delegate

  119. @sandimetz May 2016 class Foo def sales_total(params) range = DateRange.new(starting:

    params[:starting], ending: params[:ending]).range Sale.where(date: range).sum("cost") end end class Bar def weekly_sales_total(params) range = DateRange.new(starting: params[:starting]).week_range Sale.where(date: range).sum("cost") end end class Baz def expense_total(params) range = DateRange.new(starting: params[:starting], ending: params[:ending]).range Expense.where(date: range).sum("cost") end end
  120. @sandimetz May 2016 class Foo def sales_total(params) range = DateRange.new(starting:

    params[:starting], ending: params[:ending]).range Sale.where(date: range).sum("cost") end end class Bar def weekly_sales_total(params) range = DateRange.new(starting: params[:starting]).week_range Sale.where(date: range).sum("cost") end end class Baz def expense_total(params) range = DateRange.new(starting: params[:starting], ending: params[:ending]).range Expense.where(date: range).sum("cost") end end
  121. @sandimetz May 2016 Foo Sale.where(date: range).sum("cost")

  122. @sandimetz May 2016 Foo Sale Sale.where(date: range).sum("cost")

  123. @sandimetz May 2016 Foo Sale where Sale.where(date: range).sum("cost")

  124. @sandimetz May 2016 Foo Sale Persistence where Sale.where(date: range).sum("cost")

  125. @sandimetz May 2016 Foo Sale Persistence where where Sale.where(date: range).sum("cost")

  126. @sandimetz May 2016 Foo Sale Persistence where where Sale.where(date: range).sum("cost")

  127. @sandimetz May 2016 Foo Sale Persistence where where List Sale.where(date:

    range).sum("cost")
  128. @sandimetz May 2016 Foo Sale Persistence where where List Sale.where(date:

    range).sum("cost") ??? ??? ???
  129. @sandimetz May 2016 Foo Sale Persistence where where List Sale.where(date:

    range).sum("cost") ??? ??? ???
  130. @sandimetz May 2016 Foo Sale Persistence where where List Sale.where(date:

    range).sum("cost") ??? ??? ???
  131. @sandimetz May 2016 Foo Sale Persistence where where List a

    list Sale.where(date: range).sum("cost") ??? ??? ???
  132. @sandimetz May 2016 Foo Sale Persistence where where List a

    list a list Sale.where(date: range).sum("cost") ??? ??? ???
  133. @sandimetz May 2016 Foo Sale Persistence where where List sum

    a list a list Sale.where(date: range).sum("cost") ??? ??? ???
  134. @sandimetz May 2016 Foo

  135. @sandimetz May 2016 DateRange Foo

  136. @sandimetz May 2016 Sale #where DateRange Foo

  137. @sandimetz May 2016 Sale #where DateRange Foo Immediate Collaborators

  138. @sandimetz May 2016 List #sum Sale #where DateRange Foo

  139. @sandimetz May 2016 List #sum Sale #where DateRange Foo

  140. @sandimetz May 2016 List #sum Sale #where DateRange Foo Sale.where(date:

    range).sum("cost")
  141. @sandimetz May 2016 List #sum Sale #where DateRange Foo I

    know my collaborators collaborators
  142. @sandimetz May 2016 List #sum Sale #where DateRange Foo This

    is gonna hurt
  143. @sandimetz May 2016 class Foo def sales_total(params) range = DateRange.new(starting:

    params[:starting], ending: params[:ending]).range Sale.where(date: range).sum("cost") end end class Bar def weekly_sales_total(params) range = DateRange.new(starting: params[:starting]).week_range Sale.where(date: range).sum("cost") end end class Baz def expense_total(params) range = DateRange.new(starting: params[:starting], ending: params[:ending]).range Expense.where(date: range).sum("cost") end end
  144. @sandimetz May 2016 class Foo def sales_total(params) range = DateRange.new(starting:

    params[:starting], ending: params[:ending]).range Sale.where(date: range).sum("cost") end end class Bar def weekly_sales_total(params) range = DateRange.new(starting: params[:starting]).week_range Sale.where(date: range).sum("cost") end end class Baz def expense_total(params) range = DateRange.new(starting: params[:starting], ending: params[:ending]).range Expense.where(date: range).sum("cost") end end
  145. @sandimetz May 2016 class Foo def sales_total(params) range = DateRange.new(starting:

    params[:starting], ending: params[:ending]).range Sale.where(date: range).sum("cost") end end class Bar def weekly_sales_total(params) range = DateRange.new(starting: params[:starting]).week_range Sale.where(date: range).sum("cost") end end class Baz def expense_total(params) range = DateRange.new(starting: params[:starting], ending: params[:ending]).range Expense.where(date: range).sum("cost") end end
  146. @sandimetz May 2016 class Sale < Persistence def self.total(within:) where(date:

    within).sum("cost") end end class Foo def sales_total(params) range = DateRange.new(starting: params[:starting], ending: params[:ending]).range Sale.where(date: range).sum("cost") end end class Bar def weekly_sales_total(params) range = DateRange.new(starting: params[:starting]).week_range Sale.where(date: range).sum("cost") end end class Baz def expense_total(params) range = DateRange.new(starting: params[:starting], ending: params[:ending]).range Expense.where(date: range).sum("cost") end end
  147. @sandimetz May 2016 class Sale < Persistence def self.total(within:) where(date:

    within).sum("cost") end end class Foo def sales_total(params) range = DateRange.new(starting: params[:starting], ending: params[:ending]).range Sale.where(date: range).sum("cost") end end class Bar def weekly_sales_total(params) range = DateRange.new(starting: params[:starting]).week_range Sale.where(date: range).sum("cost") end end class Baz def expense_total(params) range = DateRange.new(starting: params[:starting], ending: params[:ending]).range Expense.where(date: range).sum("cost") end end
  148. @sandimetz May 2016 class Sale < Persistence def self.total(within:) where(date:

    within).sum("cost") end end class Foo def sales_total(params) range = DateRange.new(starting: params[:starting], ending: params[:ending]).range Sale.where(date: range).sum("cost") end end class Bar def weekly_sales_total(params) range = DateRange.new(starting: params[:starting]).week_range Sale.where(date: range).sum("cost") end end
  149. @sandimetz May 2016 class Sale < Persistence def self.total(within:) where(date:

    within).sum("cost") end end class Foo def sales_total(params) range = DateRange.new(starting: params[:starting], ending: params[:ending]).range Sale.where(date: range).sum("cost") end end class Bar def weekly_sales_total(params) range = DateRange.new(starting: params[:starting]).week_range Sale.where(date: range).sum("cost") end end
  150. @sandimetz May 2016 class Sale < Persistence def self.total(within:) where(date:

    within).sum("cost") end end class Foo def sales_total(params) range = DateRange.new(starting: params[:starting], ending: params[:ending]).range Sale.total(within: range) end end class Bar def weekly_sales_total(params) range = DateRange.new(starting: params[:starting]).week_range Sale.where(date: range).sum("cost") end end
  151. @sandimetz May 2016 class Sale < Persistence def self.total(within:) where(date:

    within).sum("cost") end end class Foo def sales_total(params) range = DateRange.new(starting: params[:starting], ending: params[:ending]).range Sale.total(within: range) end end class Bar def weekly_sales_total(params) range = DateRange.new(starting: params[:starting]).week_range Sale.where(date: range).sum("cost") end end
  152. @sandimetz May 2016 class Sale < Persistence def self.total(within:) where(date:

    within).sum("cost") end end class Foo def sales_total(params) range = DateRange.new(starting: params[:starting], ending: params[:ending]).range Sale.total(within: range) end end class Bar def weekly_sales_total(params) range = DateRange.new(starting: params[:starting]).week_range Sale.total(within: range) end end
  153. @sandimetz May 2016 class Sale < Persistence def self.total(within:) where(date:

    within).sum("cost") end end class Foo def sales_total(params) range = DateRange.new(starting: params[:starting], ending: params[:ending]).range Sale.total(within: range) end end class Bar def weekly_sales_total(params) range = DateRange.new(starting: params[:starting]).week_range Sale.total(within: range) end end
  154. @sandimetz May 2016 class Sale < Persistence def self.total(within:) where(date:

    within).sum("cost") end end class Foo def sales_total(params) range = DateRange.new(starting: params[:starting], ending: params[:ending]).range Sale.total(within: range) end end class Bar def weekly_sales_total(params) range = DateRange.new(starting: params[:starting]).week_range Sale.total(within: range) end end
  155. @sandimetz May 2016 class Sale < Persistence def self.total(within:) where(date:

    within).sum("cost") end end class Expense < Persistence def self.total(within:) where(date: within).sum("cost") end end class Foo def sales_total(params) range = DateRange.new(starting: params[:starting], ending: params[:ending]).range Sale.total(within: range) end end class Bar def weekly_sales_total(params) range = DateRange.new(starting: params[:starting]).week_range Sale.total(within: range) end end
  156. @sandimetz May 2016 class Sale < Persistence def self.total(within:) where(date:

    within).sum("cost") end end class Expense < Persistence def self.total(within:) where(date: within).sum("cost") end end class Foo def sales_total(params) range = DateRange.new(starting: params[:starting], ending: params[:ending]).range Sale.total(within: range) end end class Bar def weekly_sales_total(params) range = DateRange.new(starting: params[:starting]).week_range Sale.total(within: range) end end class Baz def expense_total(params) range = DateRange.new(starting: params[:starting], ending: params[:ending]).range Expense.where(date: range).sum("cost") end end
  157. @sandimetz May 2016 class Sale < Persistence def self.total(within:) where(date:

    within).sum("cost") end end class Expense < Persistence def self.total(within:) where(date: within).sum("cost") end end class Foo def sales_total(params) range = DateRange.new(starting: params[:starting], ending: params[:ending]).range Sale.total(within: range) end end class Bar def weekly_sales_total(params) range = DateRange.new(starting: params[:starting]).week_range Sale.total(within: range) end end class Baz def expense_total(params) range = DateRange.new(starting: params[:starting], ending: params[:ending]).range Expense.where(date: range).sum("cost") end end
  158. @sandimetz May 2016 class Sale < Persistence def self.total(within:) where(date:

    within).sum("cost") end end class Expense < Persistence def self.total(within:) where(date: within).sum("cost") end end class Foo def sales_total(params) range = DateRange.new(starting: params[:starting], ending: params[:ending]).range Sale.total(within: range) end end class Bar def weekly_sales_total(params) range = DateRange.new(starting: params[:starting]).week_range Sale.total(within: range) end end class Baz def expense_total(params) range = DateRange.new(starting: params[:starting], ending: params[:ending]).range Expense.total(within: range) end end
  159. @sandimetz May 2016 class Sale < Persistence def self.total(within:) where(date:

    within).sum("cost") end end class Expense < Persistence def self.total(within:) where(date: within).sum("cost") end end class Foo def sales_total(params) range = DateRange.new(starting: params[:starting], ending: params[:ending]).range Sale.total(within: range) end end class Bar def weekly_sales_total(params) range = DateRange.new(starting: params[:starting]).week_range Sale.total(within: range) end end class Baz def expense_total(params) range = DateRange.new(starting: params[:starting], ending: params[:ending]).range Expense.total(within: range) end end
  160. @sandimetz May 2016 class Sale < Persistence def self.total(within:) where(date:

    within).sum("cost") end end class Expense < Persistence def self.total(within:) where(date: within).sum("cost") end end class Foo def sales_total(params) range = DateRange.new(starting: params[:starting], ending: params[:ending]).range Sale.total(within: range) end end class Bar def weekly_sales_total(params) range = DateRange.new(starting: params[:starting]).week_range Sale.total(within: range) end end class Baz def expense_total(params) range = DateRange.new(starting: params[:starting], ending: params[:ending]).range Expense.total(within: range) end end
  161. @sandimetz May 2016 class Sale < Persistence def self.total(within:) where(date:

    within).sum("cost") end end class Expense < Persistence def self.total(within:) where(date: within).sum("cost") end end class Foo def sales_total(params) range = DateRange.new(starting: params[:starting], ending: params[:ending]).range Sale.total(within: range) end end class Bar def weekly_sales_total(params) range = DateRange.new(starting: params[:starting]).week_range Sale.total(within: range) end end class Baz def expense_total(params) range = DateRange.new(starting: params[:starting], ending: params[:ending]).range Expense.total(within: range) end end
  162. @sandimetz May 2016 class Sale < Persistence def self.total(within:) where(date:

    within).sum("cost") end end class Expense < Persistence def self.total(within:) where(date: within).sum("cost") end end class Foo def sales_total(params) range = DateRange.new(starting: params[:starting], ending: params[:ending]).range Sale.total(within: range) end end class Bar def weekly_sales_total(params) range = DateRange.new(starting: params[:starting]).week_range Sale.total(within: range) end end class Baz def expense_total(params) range = DateRange.new(starting: params[:starting], ending: params[:ending]).range Expense.total(within: range) end end Message Chain | Hide Delegate
  163. @sandimetz May 2016 4 Sidebar: How Much Reality?

  164. @sandimetz May 2016 class Sale < Persistence def self.total(within:) where(date:

    within).sum("cost") end end class Foo def sales_total(params) range = DateRange.new(starting: params[:starting], ending: params[:ending]).range Sale.total(within: range) end end
  165. @sandimetz May 2016 class Sale < Persistence def self.total(within:) where(date:

    within).sum("cost") end end class Foo def sales_total(params) range = DateRange.new(starting: params[:starting], ending: params[:ending]).range Sale.total(within: range) end end
  166. @sandimetz May 2016 class Sale < Persistence def self.total(within:) where(date:

    within).sum("cost") end end class Foo def sales_total(params) range = DateRange.new(starting: params[:starting], ending: params[:ending]).range Sale.total(within: range) end end
  167. @sandimetz May 2016 class Sale < Persistence def self.total(within:) where(date:

    within).sum("cost") end end class Foo def sales_total(params) range = DateRange.new(starting: params[:starting], ending: params[:ending]).range Sale.total(within: range) end end
  168. @sandimetz May 2016 class Sale < Persistence def self.total(within:) where(date:

    within).sum("cost") end end class Foo def sales_total(params) range = DateRange.new(starting: params[:starting], ending: params[:ending]).range Sale.total(within: range) end end # Slow Test class FooTest < Minitest::Test def test_sales_total assert_equal 28, Foo.new.sales_total(starting: "2016-04-01", ending: "2016-04-07") end end
  169. @sandimetz May 2016 class Sale < Persistence def self.total(within:) where(date:

    within).sum("cost") end end class Foo def sales_total(params) range = DateRange.new(starting: params[:starting], ending: params[:ending]).range Sale.total(within: range) end end # Slow Test class FooTest < Minitest::Test def test_sales_total assert_equal 28, Foo.new.sales_total(starting: "2016-04-01", ending: "2016-04-07") end end
  170. @sandimetz May 2016 class Sale < Persistence def self.total(within:) where(date:

    within).sum("cost") end end class Foo def sales_total(params) range = DateRange.new(starting: params[:starting], ending: params[:ending]).range Sale.total(within: range) end end # Slow Test class FooTest < Minitest::Test def test_sales_total assert_equal 28, Foo.new.sales_total(starting: "2016-04-01", ending: "2016-04-07") end end
  171. @sandimetz May 2016 class Sale < Persistence def self.total(within:) where(date:

    within).sum("cost") end end class Foo def sales_total(params) range = DateRange.new(starting: params[:starting], ending: params[:ending]).range Sale.total(within: range) end end # Slow Test class FooTest < Minitest::Test def test_sales_total assert_equal 28, Foo.new.sales_total(starting: "2016-04-01", ending: "2016-04-07") end end Check the query result
  172. @sandimetz May 2016 class Sale < Persistence def self.total(within:) where(date:

    within).sum("cost") end end class Foo def sales_total(params) range = DateRange.new(starting: params[:starting], ending: params[:ending]).range Sale.total(within: range) end end # Slow Test class FooTest < Minitest::Test def test_sales_total assert_equal 28, Foo.new.sales_total(starting: "2016-04-01", ending: "2016-04-07") end end
  173. @sandimetz May 2016 class Sale < Persistence def self.total(within:) where(date:

    within).sum("cost") end end class Foo def sales_total(params) range = DateRange.new(starting: params[:starting], ending: params[:ending]).range Sale.total(within: range) end end # Slow Test class FooTest < Minitest::Test def test_sales_total assert_equal 28, Foo.new.sales_total(starting: "2016-04-01", ending: "2016-04-07") end end
  174. @sandimetz May 2016 class Sale < Persistence def self.total(within:) where(date:

    within).sum("cost") end end class Foo def sales_total(params) range = DateRange.new(starting: params[:starting], ending: params[:ending]).range Sale.total(within: range) end end # Slow Test class FooTest < Minitest::Test def test_sales_total assert_equal 28, Foo.new.sales_total(starting: "2016-04-01", ending: "2016-04-07") end end
  175. @sandimetz May 2016 class Sale < Persistence def self.total(within:) where(date:

    within).sum("cost") end end class Foo def sales_total(params) range = DateRange.new(starting: params[:starting], ending: params[:ending]).range Sale.total(within: range) end end # Slow Test class FooTest < Minitest::Test def test_sales_total assert_equal 28, Foo.new.sales_total(starting: "2016-04-01", ending: "2016-04-07") end end Depend on Sale class?
  176. @sandimetz May 2016 class Sale < Persistence def self.total(within:) where(date:

    within).sum("cost") end end class Foo def sales_total(params) range = DateRange.new(starting: params[:starting], ending: params[:ending]).range Sale.total(within: range) end end # Slow Test class FooTest < Minitest::Test def test_sales_total assert_equal 28, Foo.new.sales_total(starting: "2016-04-01", ending: "2016-04-07") end end
  177. @sandimetz May 2016 class Sale < Persistence def self.total(within:) where(date:

    within).sum("cost") end end class Foo def sales_total(params) range = DateRange.new(starting: params[:starting], ending: params[:ending]).range Sale.total(within: range) end end # Slow Test class FooTest < Minitest::Test def test_sales_total assert_equal 28, Foo.new.sales_total(starting: "2016-04-01", ending: "2016-04-07") end end
  178. @sandimetz May 2016 class Sale < Persistence def self.total(within:) where(date:

    within).sum("cost") end end class Foo def sales_total(params) range = DateRange.new(starting: params[:starting], ending: params[:ending]).range Sale.total(within: range) end end # Slow Test class FooTest < Minitest::Test def test_sales_total assert_equal 28, Foo.new.sales_total(starting: "2016-04-01", ending: "2016-04-07") end end Depend on Totalizable role!
  179. @sandimetz May 2016 class Sale < Persistence def self.total(within:) where(date:

    within).sum("cost") end end class Foo def sales_total(params) range = DateRange.new(starting: params[:starting], ending: params[:ending]).range Sale.total(within: range) end end # Slow Test class FooTest < Minitest::Test def test_sales_total assert_equal 28, Foo.new.sales_total(starting: "2016-04-01", ending: "2016-04-07") end end
  180. @sandimetz May 2016 class Sale < Persistence def self.total(within:) where(date:

    within).sum("cost") end end class Foo def sales_total(params, model=Sale) range = DateRange.new(starting: params[:starting], ending: params[:ending]).range Sale.total(within: range) end end # Slow Test class FooTest < Minitest::Test def test_sales_total assert_equal 28, Foo.new.sales_total(starting: "2016-04-01", ending: "2016-04-07") end end
  181. @sandimetz May 2016 class Sale < Persistence def self.total(within:) where(date:

    within).sum("cost") end end class Foo def sales_total(params, model=Sale) range = DateRange.new(starting: params[:starting], ending: params[:ending]).range Sale.total(within: range) end end # Slow Test class FooTest < Minitest::Test def test_sales_total assert_equal 28, Foo.new.sales_total(starting: "2016-04-01", ending: "2016-04-07") end end
  182. @sandimetz May 2016 class Sale < Persistence def self.total(within:) where(date:

    within).sum("cost") end end class Foo def sales_total(params, model=Sale) range = DateRange.new(starting: params[:starting], ending: params[:ending]).range model.total(within: range) end end # Slow Test class FooTest < Minitest::Test def test_sales_total assert_equal 28, Foo.new.sales_total(starting: "2016-04-01", ending: "2016-04-07") end end
  183. @sandimetz May 2016 class Sale < Persistence def self.total(within:) where(date:

    within).sum("cost") end end class Foo def sales_total(params, model=Sale) range = DateRange.new(starting: params[:starting], ending: params[:ending]).range model.total(within: range) end end # Slow Test class FooTest < Minitest::Test def test_sales_total assert_equal 28, Foo.new.sales_total(starting: "2016-04-01", ending: "2016-04-07") end end
  184. @sandimetz May 2016 class Sale < Persistence def self.total(within:) where(date:

    within).sum("cost") end end class Foo def sales_total(params, model=Sale) range = DateRange.new(starting: params[:starting], ending: params[:ending]).range model.total(within: range) end end # Slow Test class FooTest < Minitest::Test def test_sales_total assert_equal 28, Foo.new.sales_total(starting: "2016-04-01", ending: "2016-04-07") end end
  185. @sandimetz May 2016 class Sale < Persistence def self.total(within:) where(date:

    within).sum("cost") end end class Foo def sales_total(params, model=Sale) range = DateRange.new(starting: params[:starting], ending: params[:ending]).range model.total(within: range) end end # Slow Test class TotalizableDouble def self.total(within:) 47 end end class FooTest < Minitest::Test def test_sales_total assert_equal 28, Foo.new.sales_total(starting: "2016-04-01", ending: "2016-04-07") end end
  186. @sandimetz May 2016 class Sale < Persistence def self.total(within:) where(date:

    within).sum("cost") end end class Foo def sales_total(params, model=Sale) range = DateRange.new(starting: params[:starting], ending: params[:ending]).range model.total(within: range) end end # Slow Test class TotalizableDouble def self.total(within:) 47 end end class FooTest < Minitest::Test def test_sales_total assert_equal 28, Foo.new.sales_total(starting: "2016-04-01", ending: "2016-04-07") end end
  187. @sandimetz May 2016 class Sale < Persistence def self.total(within:) where(date:

    within).sum("cost") end end class Foo def sales_total(params, model=Sale) range = DateRange.new(starting: params[:starting], ending: params[:ending]).range model.total(within: range) end end # Slow Test class TotalizableDouble def self.total(within:) 47 end end class FooTest < Minitest::Test def test_sales_total assert_equal 28, Foo.new.sales_total(starting: "2016-04-01", ending: "2016-04-07") end end Two players of the Totalizable role
  188. @sandimetz May 2016 class Sale < Persistence def self.total(within:) where(date:

    within).sum("cost") end end class Foo def sales_total(params, model=Sale) range = DateRange.new(starting: params[:starting], ending: params[:ending]).range model.total(within: range) end end # Slow Test class TotalizableDouble def self.total(within:) 47 end end class FooTest < Minitest::Test def test_sales_total assert_equal 28, Foo.new.sales_total(starting: "2016-04-01", ending: "2016-04-07") end end
  189. @sandimetz May 2016 class Sale < Persistence def self.total(within:) where(date:

    within).sum("cost") end end class Foo def sales_total(params, model=Sale) range = DateRange.new(starting: params[:starting], ending: params[:ending]).range model.total(within: range) end end # Slow Test class TotalizableDouble def self.total(within:) 47 end end class FooTest < Minitest::Test def test_sales_total assert_equal 28, Foo.new.sales_total(starting: "2016-04-01", ending: "2016-04-07") end end
  190. @sandimetz May 2016 class Sale < Persistence def self.total(within:) where(date:

    within).sum("cost") end end class Foo def sales_total(params, model=Sale) range = DateRange.new(starting: params[:starting], ending: params[:ending]).range model.total(within: range) end end # Slow Test class TotalizableDouble def self.total(within:) 47 end end class FooTest < Minitest::Test def test_sales_total params = {:starting => "2016-04-01", :ending => "2016-04-07"} assert_equal 28, Foo.new.sales_total(starting: "2016-04-01", ending: "2016-04-07") end end
  191. @sandimetz May 2016 class Sale < Persistence def self.total(within:) where(date:

    within).sum("cost") end end class Foo def sales_total(params, model=Sale) range = DateRange.new(starting: params[:starting], ending: params[:ending]).range model.total(within: range) end end # Slow Test class TotalizableDouble def self.total(within:) 47 end end class FooTest < Minitest::Test def test_sales_total params = {:starting => "2016-04-01", :ending => "2016-04-07"} assert_equal 28, Foo.new.sales_total(starting: "2016-04-01", ending: "2016-04-07") end end
  192. @sandimetz May 2016 class Sale < Persistence def self.total(within:) where(date:

    within).sum("cost") end end class Foo def sales_total(params, model=Sale) range = DateRange.new(starting: params[:starting], ending: params[:ending]).range model.total(within: range) end end # Slow Test class TotalizableDouble def self.total(within:) 47 end end class FooTest < Minitest::Test def test_sales_total params = {:starting => "2016-04-01", :ending => "2016-04-07"} assert_equal 28, Foo.new.sales_total(params) end end
  193. @sandimetz May 2016 class Sale < Persistence def self.total(within:) where(date:

    within).sum("cost") end end class Foo def sales_total(params, model=Sale) range = DateRange.new(starting: params[:starting], ending: params[:ending]).range model.total(within: range) end end # Slow Test class TotalizableDouble def self.total(within:) 47 end end class FooTest < Minitest::Test def test_sales_total params = {:starting => "2016-04-01", :ending => "2016-04-07"} model = TotalizableDouble assert_equal 28, Foo.new.sales_total(params) end end
  194. @sandimetz May 2016 class Sale < Persistence def self.total(within:) where(date:

    within).sum("cost") end end class Foo def sales_total(params, model=Sale) range = DateRange.new(starting: params[:starting], ending: params[:ending]).range model.total(within: range) end end # Slow Test class TotalizableDouble def self.total(within:) 47 end end class FooTest < Minitest::Test def test_sales_total params = {:starting => "2016-04-01", :ending => "2016-04-07"} model = TotalizableDouble assert_equal 28, Foo.new.sales_total(params) end end
  195. @sandimetz May 2016 class Sale < Persistence def self.total(within:) where(date:

    within).sum("cost") end end class Foo def sales_total(params, model=Sale) range = DateRange.new(starting: params[:starting], ending: params[:ending]).range model.total(within: range) end end # Slow Test class TotalizableDouble def self.total(within:) 47 end end class FooTest < Minitest::Test def test_sales_total params = {:starting => "2016-04-01", :ending => "2016-04-07"} model = TotalizableDouble assert_equal 28, Foo.new.sales_total(params, model) end end
  196. @sandimetz May 2016 class Sale < Persistence def self.total(within:) where(date:

    within).sum("cost") end end class Foo def sales_total(params, model=Sale) range = DateRange.new(starting: params[:starting], ending: params[:ending]).range model.total(within: range) end end # Slow Test class TotalizableDouble def self.total(within:) 47 end end class FooTest < Minitest::Test def test_sales_total params = {:starting => "2016-04-01", :ending => "2016-04-07"} model = TotalizableDouble assert_equal 28, Foo.new.sales_total(params, model) end end
  197. @sandimetz May 2016 class Sale < Persistence def self.total(within:) where(date:

    within).sum("cost") end end class Foo def sales_total(params, model=Sale) range = DateRange.new(starting: params[:starting], ending: params[:ending]).range model.total(within: range) end end # Slow Test class TotalizableDouble def self.total(within:) 47 end end class FooTest < Minitest::Test def test_sales_total params = {:starting => "2016-04-01", :ending => "2016-04-07"} model = TotalizableDouble assert_equal 47, Foo.new.sales_total(params, model) end end
  198. @sandimetz May 2016 class Sale < Persistence def self.total(within:) where(date:

    within).sum("cost") end end class Foo def sales_total(params, model=Sale) range = DateRange.new(starting: params[:starting], ending: params[:ending]).range model.total(within: range) end end # Slow Test class TotalizableDouble def self.total(within:) 47 end end class FooTest < Minitest::Test def test_sales_total params = {:starting => "2016-04-01", :ending => "2016-04-07"} model = TotalizableDouble assert_equal 47, Foo.new.sales_total(params, model) end end FAST
  199. @sandimetz May 2016 class Sale < Persistence def self.total(within:) where(date:

    within).sum("cost") end end class Foo def sales_total(params, model=Sale) range = DateRange.new(starting: params[:starting], ending: params[:ending]).range model.total(within: range) end end # Slow Test class TotalizableDouble def self.total(within:) 47 end end class FooTest < Minitest::Test def test_sales_total params = {:starting => "2016-04-01", :ending => "2016-04-07"} model = TotalizableDouble assert_equal 47, Foo.new.sales_total(params, model) end end
  200. @sandimetz May 2016 class Sale < Persistence def self.total(within:) where(date:

    within).sum("cost") end end class Foo def sales_total(params, model=Sale) range = DateRange.new(starting: params[:starting], ending: params[:ending]).range model.total(within: range) end end # FAST Test class TotalizableDouble def self.total(within:) 47 end end class FooTest < Minitest::Test def test_sales_total params = {:starting => "2016-04-01", :ending => "2016-04-07"} model = TotalizableDouble assert_equal 47, Foo.new.sales_total(params, model) end end
  201. @sandimetz May 2016 5 Duplicated Code | Pull Up Method

  202. @sandimetz May 2016 class Sale < Persistence def self.total(within:) where(date:

    within).sum("cost") end end class Expense < Persistence def self.total(within:) where(date: within).sum("cost") end end
  203. @sandimetz May 2016 class Sale < Persistence def self.total(within:) where(date:

    within).sum("cost") end end class Expense < Persistence def self.total(within:) where(date: within).sum("cost") end end
  204. @sandimetz May 2016 class Sale < Persistence def self.total(within:) where(date:

    within).sum("cost") end end class Expense < Persistence def self.total(within:) where(date: within).sum("cost") end end
  205. @sandimetz May 2016 class Sale < Persistence def self.total(within:) where(date:

    within).sum("cost") end end class Expense < Persistence def self.total(within:) where(date: within).sum("cost") end end
  206. @sandimetz May 2016 module Totalable def total(within:, date_field: :date, on:

    "cost") where({date_field => within}).sum(on) end end class Sale < Persistence def self.total(within:) where(date: within).sum("cost") end end class Expense < Persistence def self.total(within:) where(date: within).sum("cost") end end
  207. @sandimetz May 2016 module Totalable def total(within:, date_field: :date, on:

    "cost") where({date_field => within}).sum(on) end end class Sale < Persistence def self.total(within:) where(date: within).sum("cost") end end class Expense < Persistence def self.total(within:) where(date: within).sum("cost") end end
  208. @sandimetz May 2016 module Totalable def total(within:, date_field: :date, on:

    "cost") where({date_field => within}).sum(on) end end class Sale < Persistence def self.total(within:) where(date: within).sum("cost") end end class Expense < Persistence def self.total(within:) where(date: within).sum("cost") end end
  209. @sandimetz May 2016 module Totalable def total(within:, date_field: :date, on:

    "cost") where({date_field => within}).sum(on) end end class Sale < Persistence def self.total(within:) where(date: within).sum("cost") end end class Expense < Persistence def self.total(within:) where(date: within).sum("cost") end end Speculative Generality
  210. @sandimetz May 2016 module Totalable def total(within:, date_field: :date, on:

    "cost") where({date_field => within}).sum(on) end end class Sale < Persistence def self.total(within:) where(date: within).sum("cost") end end class Expense < Persistence def self.total(within:) where(date: within).sum("cost") end end Dependency Injection Is Awesome
  211. @sandimetz May 2016 module Totalable def total(within:, date_field: :date, on:

    "cost") where({date_field => within}).sum(on) end end class Sale < Persistence end class Expense < Persistence end
  212. @sandimetz May 2016 module Totalable def total(within:, date_field: :date, on:

    "cost") where({date_field => within}).sum(on) end end class Sale < Persistence extend Totalable end class Expense < Persistence extend Totalable end
  213. @sandimetz May 2016 module Totalable def total(within:, date_field: :date, on:

    "cost") where({date_field => within}).sum(on) end end class Sale < Persistence extend Totalable end class Expense < Persistence extend Totalable end
  214. @sandimetz May 2016 module Totalable def total(within:, date_field: :date, on:

    "cost") where({date_field => within}).sum(on) end end class Sale < Persistence extend Totalable end class Expense < Persistence extend Totalable end Duplicated Code | Pull Up Method
  215. @sandimetz May 2016 Code Smell Curative Refactoring Recipe

  216. @sandimetz May 2016

  217. @sandimetz May 2016 class DateRange attr_reader :starting, :ending def initialize(starting:,

    ending: nil) @starting = Date.parse(starting) rescue Date.today @ending = Date.parse(ending) rescue @starting end def range starting..ending end def week_range starting..(starting + 6) end end
  218. @sandimetz May 2016 module Totalable def total(within:, date_field: :date, on:

    "cost") where({date_field => within}).sum(on) end end class Sale < Persistence extend Totalable end class Expense < Persistence extend Totalable end
  219. @sandimetz May 2016 class Foo def sales_total(params, model=Sale) range =

    DateRange.new(starting: params[:starting], ending: params[:ending]).range model.total(within: range) end end class Bar def weekly_sales_total(params, model=Sale) range = DateRange.new(starting: params[:starting]).week_range model.total(within: range) end end class Baz def expense_total(params, model=Expense) range = DateRange.new(starting: params[:starting], ending: params[:ending]).range model.total(within: range) end end
  220. @sandimetz May 2016 Fist Pump

  221. @sandimetz May 2016 Fist Pump

  222. @sandimetz May 2016

  223. @sandimetz May 2016 Reek

  224. @sandimetz May 2016

  225. @sandimetz May 2016

  226. @sandimetz May 2016

  227. @sandimetz May 2016

  228. @sandimetz Thanks May 2016

  229. @sandimetz References May 2016 http://martinfowler.com/books/refactoring.html http://www.refactoringinruby.info/ Kevin Rutherford, William Wake

    Mäntylä, M. V. and Lassenius, C. "Subjective Evaluation of Software Evolvability Using Code Smells: An Empirical Study". Journal of Empirical Software Engineering, vol. 11, no. 3, 2006, pp. 395-431. https://github.com/troessner/reek https://blog.codeship.com/how-to-find-ruby-code-smells-with-reek
  230. @sandimetz Credits May 2016 Coffee on a Winter's morning, Stefan

    Lins, https://www.flickr.com/photos/mrlins/8533102693/ Royal Australian Air Force in Australia during World War II, Argus Newspaper Collection of Photographs, State Library of Victoria, https://www.flickr.com/photos/statelibraryofvictoria_collections/16554906225/ Chevy Crusher, Ruby Eng , https://www.flickr.com/photos/mac-ash/4105522760/ Misuse Makes Mishaps, Jeremy Brooks , https://www.flickr.com/photos/jeremybrooks/2205135193, resistance is futile, Lora, https://www.flickr.com/photos/laroyo/6871150550/ Well this is pointless, Janet McKnight, https://www.flickr.com/photos/janetmck/2613441853/ Glue goo 3, Sam-Cat, https://www.flickr.com/photos/samcatchesides/3326878644/ poses of victory, Daniel Novta, https://www.flickr.com/photos/vanf/7304661962/ Odorous smells!, auddess, https://www.flickr.com/photos/auddess/4744679975 EXPLORE] Smell the Flowers, Christine und David Schmitt, https://www.flickr.com/photos/cheesy42/8624536219/ PIZZA, Tobi Gaulke. https://www.flickr.com/photos/gato-gato-gato/15958062095/ Ain't Life Grand, Anne Worner, https://www.flickr.com/photos/wefi_official/9305161946/
  231. @sandimetz http://poodr.com May 2016

  232. @sandimetz http://99bottlesbook.com May 2016

  233. @sandimetz Sandi Metz @sandimetz http://sandimetz.com May 2016

  234. @sandimetz Questions? May 2016

  235. @sandimetz Sandi Metz @sandimetz http://sandimetz.com May 2016