RubyFlow The Ruby and Rails community linklog

Named Scopes Are Dead

Lots of people love using named scopes in Rails 2. However, in Rails 3 they’re not only more or less obsolete but can also hinder productiveness in teams by being update blockers. Read about the reasons and alternatives in the railway blog.

Comments

When I first gave AR 3 a go, I wondered if you could just use class methods for the same benefits as scopes considering the lazy evaluation. Glad someone else actually tried it and confirms it works ;-) That class << self stuff is a big gangly though.. def self.published reads somewhat nicer.

That class « self stuff is a big gangly though.. def self.published reads somewhat nicer.

I agree with you on this one but I have seen several posts which suggest that this is not the best practice… (I have yet to understand why).

Peter: I prefer class « self simply to keep things more organized – all class methods in one place (alright, alright, meta class’ instance methods ;-)). And they’re easier to grep for – it’s always def whatever, no difference between instance and class methods.

Nothing wrong with a preference, of course, but it’s still more verbose (and if used in anger leads to situations where you’re not entirely sure if a method is a class or instance method, unless you go looking for the associated class definition).

Post a comment

You can use basic HTML markup (e.g. <a>) or Markdown.

As you are not logged in, you will be
directed via GitHub to signup or sign in