What's the :: symbol on Geom::....
-
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
-
Best not to think about it too much...
Just follow the usual conventions [some are interchangeable ]...Geom
andSketchup
are examples of a 'module'...Geom::Transformation
andSketchup::Face
are examples of a class [this uses a :: separator]Geom.intersect_line_plane()
andGeom::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. -
@abakobo said:
what's behind the
::
symbol inGeom
?It is called the scope operator.
::
with nothing to the left of it means the top level scope (akaTOPLEVEL_BINDING
,) which is "a particular instance ofObject
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 thePoint3d
class, within theGeom
module scope.@abakobo said:
and when do we use
::
and/or.
to call a methodIt's style, but many people only use the
.
for ALL methods.Some people use
::
for calling module functions and class methods (which thenew
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.)
Advertisement