This project is archived and is in readonly mode.

#4083 ✓resolved

[Patch] Named Scopes should be allowed to overwrite an existing method

Reported by MatthewRudy | March 2nd, 2010 @ 03:38 AM

I wrote a little blog post on this
but it's motivated by the following case

class MyClass < ActiveRecord::Base
  scope :open, :conditions => "start_date <= CURRENT_DATE"

I think this is a common pattern.
the word "open" makes sense in some cases,
more so than "active".

But in Rails 3 this doesn't work

/Users/matthew/.bundle/ruby/1.8/bundler/gems/rails-16a5e918a06649ffac24fd5873b875daf66212ad-master/activerecord/lib/active_record/named_scope.rb:104:in `scope’: Cannot define scope :open because method already exists. (ArgumentError)

This is because

>> MyClass.private_methods.include?("open")
=> true
>> "some string".private_methods.include?("open")
=> true

Everything has a private method called "open".

So what's the right solution.
I claim that I should be allowed to define a method of any particular name,
if I break something by overwriting an existing method,
then that's a mistake of mine
and I hope my testing will pick it up.

I claim a logger.warn is the correct functionality.

My branch to fix this:
My commit to fix this:

Also attached as a patch

Comments and changes to this ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href=""></a>

People watching this ticket


Referenced by