I just released a #Ruby Gem to detect pending #...
Capistrano Detect Migrations lets you detect pending Rails migrations before you deploy to any remote hosts. It leverages ...
April 11, 2012 Tagged: patterns refactoring null object Comments (View) Rails Refactoring Example: Introduce Null Object You probably don’t write code like this: if object.kind_of?(User) do_this else object.do_that end Why not? Because Ruby encourages duck typing and polymorphism. A hidden version Here’s the same principle: if object.nil? do_this else object.do_that else This checks that object is of type NilClass instead of type User . The pattern There’s an old pattern called Null Object that addresses this special case of avoiding type-checking in favor of duck typing. Here’s an example of the “Introduce Null Object” refactoring to fix this problem with a Null Object in a Rails app. The code to be refactored Airbrake reports an error from this line in a Haml view: = l location.orders.ascend_by_created_at.first.created_at.to_date Demeter is displeased but let’s fix the p...
Full article: http://robots.thoughtbot.com/post/20907555103/rails-refac...
@filiptepper
»
18 Apr '12, 6pm
@kevinrutherford
»
15 Apr '12, 9am
@tripping_ba11s
»
12 Apr '12, 12am
@RubyReflector
»
11 Apr '12, 6pm
@Duncan_ita
»
16 Apr '12, 10am
Capistrano Detect Migrations lets you detect pending Rails migrations before you deploy to any remote hosts. It leverages ...