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? -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/wlt_OKxI1FsJ. For more options, visit https://groups.google.com/groups/opt_out.
On 11 March 2013 07:30, powi <corestudiosinc-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> 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?I can''t seem to find the docs for default_scopes? Can you point me to it? Colin -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.
It''s not documented since it''s dynamically defined. On Monday, 11 March 2013 12:14:02 UTC+2, Colin Law wrote:> > On 11 March 2013 07:30, powi <corestu...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org <javascript:>> wrote: > > 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? > > I can''t seem to find the docs for default_scopes? Can you point me to it? > > Colin >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/lz-Pxdf1lccJ. For more options, visit https://groups.google.com/groups/opt_out.
On 11 March 2013 21:26, powi <corestudiosinc-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> 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> > On Monday, 11 March 2013 12:14:02 UTC+2, Colin Law wrote: >> >> On 11 March 2013 07:30, powi <corestu...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> > 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? >> >> I can''t seem to find the docs for default_scopes? Can you point me to it? >> >> Colin-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.
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) On Monday, 11 March 2013 23:48:37 UTC+2, Colin Law wrote:> > On 11 March 2013 21:26, powi <corestu...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org <javascript:>> 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 > > > > > On Monday, 11 March 2013 12:14:02 UTC+2, Colin Law wrote: > >> > >> On 11 March 2013 07:30, powi <corestu...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > >> > 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? > >> > >> I can''t seem to find the docs for default_scopes? Can you point me to > it? > >> > >> Colin >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/vazqtvbBHnMJ. For more options, visit https://groups.google.com/groups/opt_out.
On 12 March 2013 16:39, powi <corestudiosinc-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> 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. Colin> > > On Monday, 11 March 2013 23:48:37 UTC+2, Colin Law wrote: >> >> On 11 March 2013 21:26, powi <corestu...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> 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 >> >> > >> > On Monday, 11 March 2013 12:14:02 UTC+2, Colin Law wrote: >> >> >> >> On 11 March 2013 07:30, powi <corestu...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> >> > 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? >> >> >> >> I can''t seem to find the docs for default_scopes? Can you point me to >> >> it? >> >> >> >> Colin-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.