sketchucation logo sketchucation
    • Login
    ℹ️ Licensed Extensions | FredoBatch, ElevationProfile, FredoSketch, LayOps, MatSim and Pic2Shape will require license from Sept 1st More Info

    What's the :: symbol on Geom::....

    Scheduled Pinned Locked Moved Developers' Forum
    3 Posts 3 Posters 315 Views 3 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.
    • A Offline
      abakobo
      last edited by

      hi everybody, i'm new on the forum!

      thanks for the time you spend on forum's...

      here's my question

      what's behind the :: symbol in Geom?

      ex:
      *line1 = [Geom::Point3d.new(0,0,0), Geom::Vector3d.new(0,0,1)]
      line2 = [Geom::Point3d.new(0,0,0), Geom::Vector3d.new(0,0,100)]

      0,0,0 on each line should be closest because both lines start from

      that point

      pts = Geom.closest_points line1, line2*

      and when do we use :: and/or . to call a method
      is it only when using new or is it more subtle?

      grtz

      abakobo

      1 Reply Last reply Reply Quote 0
      • TIGT Online
        TIG Moderator
        last edited by

        Best not to think about it too much... πŸ˜’
        Just follow the usual conventions [some are interchangeable πŸ˜• ]...

        Geom and Sketchup
        are examples of a 'module'...

        Geom::Transformation and Sketchup::Face
        are examples of a class [this uses a :: separator]

        Geom.intersect_line_plane() and Geom::Transformation.translation()
        is a method (def) [this uses a . separator]

        Sketchup::Face::PointUnknown
        is a Fixnum [this is a Constant that is used in face.classify_point result tests]

        You can also use it to return a module's @var reference's value, but only if a suitable 'attr_accessor' has been setup in the code...
        For example: TIG::MyXtool.xyz
        [this is a module containing a module, with a :: separator, then a . to give the reference]

        Tip:
        Modules and Classes will start with a Capital letter.
        Methods etc will start with a lower case letter.

        TIG

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

          @abakobo said:

          what's behind the :: symbol in Geom ?

          It is called the scope operator.

          :: with nothing to the left of it means the top level scope (aka TOPLEVEL_BINDING,) which is "a particular instance of Object called 'main'".
          But it's use that way is optional. Ruby always checks the current scope first, then the top level scope if it needs to.

          But this is also why you should always be executing YOUR code inside a toplevel module, with some unique name that you invent. like
          module Abakobo

          So Geom::Point3d is referring to the Point3d class, within the Geom module scope.

          @abakobo said:

          and when do we use :: and/or . to call a method

          It's style, but many people only use the . for ALL methods.

          Some people use :: for calling module functions and class methods (which the new constructor is,) and then use . to call only instance methods. (Some of the older examples, from the days when SketchUp was owned by Google or @Last Software, use this latter convention. I guess they wanted to emphasize the calling of class methods or module functions.)

          πŸ’­

          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