ActiveRecord::Base.default_scopes?

17 views
Skip to first unread message

powi

unread,
Mar 11, 2013, 3:30:03 AM3/11/13
to rubyonra...@googlegroups.com
ActiveRecord models has a weird behavior.

class Post < ActiveRecord::Base
end

% Post.default_scopes? # => true

This happens because Post.default_scopes returns an empty array and .default_scopes? calls !![] which is true. But this can be confusing, don't you think?

Colin Law

unread,
Mar 11, 2013, 6:14:02 AM3/11/13
to rubyonra...@googlegroups.com
I can't seem to find the docs for default_scopes? Can you point me to it?

Colin

powi

unread,
Mar 11, 2013, 5:26:37 PM3/11/13
to rubyonra...@googlegroups.com, cla...@googlemail.com
It's not documented since it's dynamically defined.

Colin Law

unread,
Mar 11, 2013, 5:48:37 PM3/11/13
to powi, rubyonra...@googlegroups.com
On 11 March 2013 21:26, powi <corestu...@gmail.com> wrote:
> It's not documented since it's dynamically defined.

Many dynamically defined methods are documented in various places (in
the Rails Guides for example).
If it is not documented how am I supposed to know how what it does?

Colin

powi

unread,
Mar 12, 2013, 12:39:25 PM3/12/13
to rubyonra...@googlegroups.com, powi, cla...@googlemail.com
I'm sorry but I didn't wrote these methods.

However, you can still understand what it does by:
  1. using it in the rails console
  2. reading the source
  3. reading its name (in this particular occasion, it's very obvious)

Colin Law

unread,
Mar 12, 2013, 12:50:00 PM3/12/13
to powi, rubyonra...@googlegroups.com
On 12 March 2013 16:39, powi <corestu...@gmail.com> wrote:
> I'm sorry but I didn't wrote these methods.
>
> However, you can still understand what it does by:
>
> using it in the rails console
> reading the source
> reading its name (in this particular occasion, it's very obvious)

Generally I assume that if a method is not documented anywhere then it
is probably not intended to be used by lesser mortals, and may be
liable to change without warning, and therefore I do not care what the
interface is. Perhaps that is not be a reasonable stance to take
however.
Reply all
Reply to author
Forward
0 new messages