Fri26Mar

  1. To Yield Or Not To Yield? That Is The Question…

    Today I was looking quite closely at Rails 3, specifically the changes to the routing API.

    # Rails 2.x
    ActionController::Routing::Routes.draw do |map|
      map.resources :posts
    end
    
    # Rails 3.x
    AppName::Application.routes do
      resources :posts
    end
    

    The first thing I noticed was the omission of a block variable. So I thought to myself “WTF? Is the block being instance_eval’ed instead of yielded to?”

    Yes, it turns out it is, well instance_exec‘ed to be precise. I always thought instance_eval’ing a block was an antipattern

    So why the change? Is this still representative of current thinking?