For example, you see files called

rails/actionpack/lib/action_controller/base.rb

which adds methods and such to the open module ActionController. What
scope is ActionController in? Is it just called the global scope?
Obviously, there is namespace resolution lookup. And a good example of
this is in the Base class of the same file. It references one module
like this: AbstractController::Layouts and another module like this:
Rendering. One uses the :: namespace resolution operator, because
Layouts module is not within the scope that class Base is, which is
module ActionController scope, so it has to reference
AbstractController which must be in the GLOBAL scope in order for ruby
to find it and then it can look there to find Layouts. In contrast,
Rendering is defined within the ActionController scope, and since
class Base is defined within the ActionController scope as well, it
doesn't need to use the :: operator. It can simply search within that
scope and find the module Rendering. So what is that global scope that
ActionController and AbstractController are in within Rails?

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Search Discussions

  • John Merlino at Sep 27, 2012 at 12:29 am
    Top-level methods or constants defined outside of any class or module
    are implicitly defined in Object.
    On Sep 21, 1:30 pm, John Merlino wrote:
    For example, you see filescalled

    rails/actionpack/lib/action_controller/base.rb

    which adds methods and such to the open module ActionController. Whatscopeis ActionController in? Is it justcalledtheglobalscope?
    Obviously, there is namespace resolution lookup. And a good example of
    this is in the Base class of the same file. It references one module
    like this: AbstractController::Layouts  and another module like this:
    Rendering. One uses the :: namespace resolution operator, because
    Layouts module is not within thescopethat class Base is, which is
    module ActionControllerscope, so it has to reference
    AbstractController which must be in theGLOBALscopein order for ruby
    to find it and then it can look there to find Layouts. In contrast,
    Rendering is defined within the ActionControllerscope, and since
    class Base is defined within the ActionControllerscopeas well, it
    doesn't need to use the :: operator. It can simply search within thatscopeand find the module Rendering. So what is thatglobalscopethat
    ActionController and AbstractController are in withinRails?
    --
    You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
  • 7stud -- at Sep 27, 2012 at 4:47 am
    Methods attach themselves to whatever the current class is when they are
    defined. If self is a class when the method is defined, then the method
    becomes an instance method in that class. If self is not a class when
    the method is defined, then the current class is self's class.


    puts self
    puts self.class

    --output:--
    main
    Object


    def do_stuff
    end

    self is the object called 'main', which ruby creates for you on startup,
    and it is not a class, so do_stuff() attaches to self's class, which is
    Object.

    --
    Posted via http://www.ruby-forum.com/.

    --
    You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouprubyonrails-talk @
categoriesrubyonrails
postedSep 21, '12 at 5:29p
activeSep 27, '12 at 4:47a
posts3
users2
websiterubyonrails.org
irc#RubyOnRails

2 users in discussion

John Merlino: 2 posts 7stud --: 1 post

People

Translate

site design / logo © 2022 Grokbase