🕷 zenspider.com

by ryan davis



sitemap
Looking for the Ruby Quickref?

readability vs. speed

Published 2007-09-17 @ 21:04

Tagged rails, ruby

Which one is better? You decide…

  if true then # 0.75 seconds
    require 'active_record'
    require 'yaml'
    require 'app/models/author'
    require 'app/models/project'
    config = YAML.load(File.read('config/database.yml'))
    ActiveRecord::Base.establish_connection(config["development"])
  else # 2.0 seconds
    require File.dirname(__FILE__) + '/../config/environment'
  end
  
  conn = ActiveRecord::Base.connection

I’m slightly partial to the faster running one (esp. during development)… but it did take me a while to figger it out. Loading config/environment a heavy price to pay just to get a DB connection and automatic requires.