sketchucation logo sketchucation
    • Login
    โ„น๏ธ Licensed Extensions | FredoBatch, ElevationProfile, FredoSketch, LayOps, MatSim and Pic2Shape will require license from Sept 1st More Info

    Module.foobar vs Module::foobar ?

    Scheduled Pinned Locked Moved Developers' Forum
    12 Posts 6 Posters 663 Views 6 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • thomthomT Offline
      thomthom
      last edited by

      
      module Foo
      
        def self.bar
          puts 'Hello World'
        end
      
      end
      
      

      Is there any difference to calling Foo.bar vs Foo::bar ?

      Thomas Thomassen โ€” SketchUp Monkey & Coding addict
      List of my plugins and link to the CookieWare fund

      1 Reply Last reply Reply Quote 0
      • M Offline
        MartinRinehart
        last edited by

        They are sometimes synonymous. The . form is preferred if you are calling a method Module should reasonably be expected to perform, especially one that changes Module. The :: suggests that you are calling a service provided by Module.

        Author, Edges to Rubies - The Complete SketchUp Tutorial at http://www.MartinRinehart.com/models/tutorial.

        1 Reply Last reply Reply Quote 0
        • thomthomT Offline
          thomthom
          last edited by

          A "service"? That does that mean in Ruby world?

          Thomas Thomassen โ€” SketchUp Monkey & Coding addict
          List of my plugins and link to the CookieWare fund

          1 Reply Last reply Reply Quote 0
          • M Offline
            MartinRinehart
            last edited by

            @thomthom said:

            A "service"? That does that mean in Ruby world?

            It puts "Hello, World!" to the console. It doubles the size of a ComponentInstance along an axis. It returns the value of pi to a ridiculous number of decimal places.

            Author, Edges to Rubies - The Complete SketchUp Tutorial at http://www.MartinRinehart.com/models/tutorial.

            1 Reply Last reply Reply Quote 0
            • J Offline
              Jim
              last edited by

              @martinrinehart said:

              It puts "Hello, World!" to the console. It doubles the size of a ComponentInstance along an axis. It returns the value of pi to a ridiculous number of decimal places.

              You've just described a 'method'.

              Hi

              1 Reply Last reply Reply Quote 0
              • J Offline
                Jim
                last edited by

                The :: is the scope operator. Isn't the . (dot) an operator meaning "send this message to the receiver."?

                Here's something:
                http://stackoverflow.com/questions/43134/is-there-a-difference-between-and-when-calling-class-methods-in-ruby

                Hi

                1 Reply Last reply Reply Quote 0
                • thomthomT Offline
                  thomthom
                  last edited by

                  I still don't understand what the difference between calling a method with :: vs . is... ๐Ÿ˜•

                  Thomas Thomassen โ€” SketchUp Monkey & Coding addict
                  List of my plugins and link to the CookieWare fund

                  1 Reply Last reply Reply Quote 0
                  • J Offline
                    jessejames
                    last edited by

                    @thomthom said:

                    I still don't understand what the difference between calling a method with :: vs . is... ๐Ÿ˜•

                    That because of Tim Toady. When there are so many ways to do the same thing it makes learning the "thing" (in this case Ruby) extremely complicated. In Python we use the "DOT" to call modules, classes, methods, and functions. Also we use the identifier without parenthesis to get a reference to a class, method, or function. (no symbols needed!). Our built-ins have just enough methods and NOT too many for good reason. And we never have more than one method that does exactly the same thing ...like the following (Note: "S" is the Selection instance)

                    1. S#at(idx) and S#[idx]
                    2. S#count() and S#length() and S#nitems() ๐Ÿคข
                    3. S#single_object? and S#length|nitems|count == 1
                    4. S#empty? and S#length|nitems|count == 0
                    5. S#each{...} and for x in selection...end
                    6. S#include?(obj) and S#contains?(obj)
                    7. S#first() and begin S#[0] rescue nil end
                    8. the unexpected rules for add and remove ๐Ÿ‘Š
                      ๐Ÿ˜† ๐Ÿ˜„ ๐Ÿ˜„ ๐Ÿ˜• ๐Ÿ˜ฒ ๐Ÿ˜ฎ ๐Ÿ˜  ๐Ÿ˜ก ๐Ÿ˜ž ๐Ÿ˜ข ๐Ÿ˜’

                    Just image for a moment if instead of just 'Yield!' signs we also had "Look Out!", "Be Careful!", "Submit!", "Bend Over!", "FIFO", "VIP's first", "Take it Like a man!". Well at least then folks would have an excuse for not reading and obeying the signs!

                    Always sleep with a loaded gun under your pillow!

                    1 Reply Last reply Reply Quote 0
                    • Dan RathbunD Offline
                      Dan Rathbun
                      last edited by

                      @thomthom said:

                      I still don't understand what the difference between calling a method with :: vs . is... ๐Ÿ˜•

                      From "Programming Ruby : The Pragmatic Programmer's Guide"

                      @unknownuser said:

                      (http://phrogz.net/ProgrammingRuby/language.html#therubylanguage) 'Invoking a Method'":385b8bf0]A method is called by passing its name to a receiver. If no receiver is specified, self is assumed.

                      The receiver checks for the method definition in its own class and then sequentially in its ancestor classes. The instance methods of included modules act as if they were in anonymous superclasses of the class that includes them. If the method is not found, Ruby invokes the method method_missing in the receiver. The default behavior defined in Kernel::method_missing is to report an error and terminate the program.

                      When a receiver is explicitly specified in a method invocation, it may be separated from the method name using either a period "." or two colons "::". The only difference between these two forms occurs if the method name starts with an uppercase letter. In this case, Ruby will assume that a receiver::Thing method call is actually an attempt to access a constant called Thing in the receiver unless the method invocation has a parameter list between parentheses.

                      I'm not here much anymore.

                      1 Reply Last reply Reply Quote 0
                      • thomthomT Offline
                        thomthom
                        last edited by

                        Thanks Dan. That put my mind at rest. ๐Ÿ‘

                        Thomas Thomassen โ€” SketchUp Monkey & Coding addict
                        List of my plugins and link to the CookieWare fund

                        1 Reply Last reply Reply Quote 0
                        • JD HillJ Offline
                          JD Hill
                          last edited by

                          Module.foobar is an alias for Module::foobar, which is itself an alias for Ruby::is_fubar?, which incidentally, always returns the TrueClass instance, for which jessejames's above statement is an alias.

                          Developer - Bella Render

                          1 Reply Last reply Reply Quote 0
                          • Dan RathbunD Offline
                            Dan Rathbun
                            last edited by

                            @jd hill said:

                            ..., for which jessejames's above statement is an alias.

                            LOL ~ ๐Ÿคฃ

                            I'm not here much anymore.

                            1 Reply Last reply Reply Quote 0
                            • 1 / 1
                            • First post
                              Last post
                            Buy SketchPlus
                            Buy SUbD
                            Buy WrapR
                            Buy eBook
                            Buy Modelur
                            Buy Vertex Tools
                            Buy SketchCuisine
                            Buy FormFonts

                            Advertisement