Pollution Private methods of Class
-
Something strange I just noticed.
All classes seems to have a lot of private methods which apparently derive from some existing scripts.
For instance, if in the Ruby Console you just create an empty class
class FooClass ; end
....and then check its private methods:
FooClass.private_methods
...Then you get this long list, in which you have only a few Ruby built-in methods, all others coming from installed scripts:
%(#0000FF)[chop!
loop
lambda
printf
FacesAreTriangles
method_undefined
private
linestyletool2D
In2DCircle
method_missing
untrace_var
throw
chop
format
sleep
sign
freehandtool2D
extrude_test
wd
helix
warn
chomp!
trap
remove_instance_variable
print
NegIfEven
texttool2D
set_trace_func
test
GetPolyNormal
chomp
Equal2D2
wp
initialize
global_variables
load
arctool2D
wpp
polylineedittool2D
points_on_circle
remove_method
raise
extrudeEdgesByLathe
GetTransformedVertexPositions
putc
extrudeEdgesByFace
Integer
remove_class_variable
OrderConnectedEdges
CheckEntity
GetFaceNormal
getOffsetPolygon2
PointInArray
inherited
local_variables
require
circletool2D
extrudeEdgesByFaces
undef_method
require_all
exit!
scan
fail
attr
GetCursorID
CalcTriangleProperties
puts
class_variable_get
Float
create_face_from_selection
join_edges
GetAllVertices
`
initialize_copy
extrudeEdgesByEdges
polygontool2D
alias_method
caller
attr_reader
simplyContours
getOffsetPolygon
gets
class_variable_set
String
SelectAllConnected
CountDuplicates
line2cyl
deBabelizer
included
VectorScalarMult
facemakertool2D
define_method
InPlane
extrudeEdgesByLoft
exit
fork
LineFaceIntersection
attr_writer
readline
PutsTransform
singleton_method_added
SimplifyCurve
Array
eval
split
extrudeEdgesByRails
getc
extended
include
isOdd
getOffsetPolygon3
hatchingtool2D
tellPctComplete
show_ruby_panel
create_box
callcc
file_loaded?
attr_accessor
abort
singleton_method_removed
readlines
zplane2D
file_loaded
IsAlreadySelected
sub!
binding
syscall
srand
RemoveNonFunctionalVerts
select
GetVertsInWCS
GetFaces
method_added
public
extrudeEdgesByRailsByFace
SegmentsCross2D
fillettool2D
extrudeEdgesByRailsToLattice
make_pano_pm
sub
Equal2D
at_exit
p
linetool2D
extrudeEdgesByVector
revolve_test
iterator?
singleton_method_undefined
exec
gsub!
proc
make_selected_components_unique
rand
TriangulateDelaunay
open
paramT
remove_const
method_removed
protected
adjusttool2D
trace_var
catch
gsub
block_given?
system
rectangletool2D
inputbox
sprintf
add_separator_to_menu]I don't know where it comes from? I guess this is because these methods are created at Object class level.
Fredo
PS: I discovered this accidentally, because I wanted to call the private method
"remove_method"
from within a clas, but without success. -
@unknownuser said:
All classes seems to have a lot of private methods which apparently derive from some existing scripts.
No kidding! I (and others,) have been screaming about this for years? It's why we try to catch newbies, right away, and get them to code within their own module namespace.
@unknownuser said:
I don't know where it comes from? I guess this is because these methods are created at Object class level
Yes.. when a script is loaded.. it is evaluated within
TOPLEVEL_BINDING
, which "is the particular instance ofObject
, called 'main
'"So any instance vars, class vars, local vars, constants, methods, that are not wrapped in a namespace, are GLOBAL.
We are fighting a losing battle against the poorly written Ruby examples, distributed by the SketchUp Development Team. Many of the examples are not namespace wrapped. Some of the extensions are not namespace wrapped (Sandbox Tools & ACT which is why I have them turned OFF.)
You can use the boolean arguments to help filter out methods you do not wish to see:
FooClass.private_methods.sort - private_methods(false).sort
-
Dan,
Thanks. Here is the list of the alien methods in my Sketchup environment.
Indeed, there may be others as I only use a few scripts.
The command for getting the list in the Ruby console is
class FooClass ; end (FooClass.private_methods & private_methods(false)).sort.join "\n"
Fredo
=====================================================================
List of foreign methods inherited by all classes on Fredo6 machineCalcTriangleProperties
CheckEntity
CountDuplicates
Equal2D
Equal2D2
FacesAreTriangles
GetAllVertices
GetCursorID
GetFaceNormal
GetFaces
GetPolyNormal
GetTransformedVertexPositions
GetVertsInWCS
In2DCircle
InPlane
IsAlreadySelected
LineFaceIntersection
NegIfEven
OrderConnectedEdges
PointInArray
PutsTransform
RemoveNonFunctionalVerts
SegmentsCross2D
SelectAllConnected
SimplifyCurve
TriangulateDelaunay
VectorScalarMult
add_separator_to_menu
adjusttool2D
arctool2D
circletool2D
create_box
create_face_from_selection
deBabelizer
extrudeEdgesByEdges
extrudeEdgesByFace
extrudeEdgesByFaces
extrudeEdgesByLathe
extrudeEdgesByLoft
extrudeEdgesByRails
extrudeEdgesByRailsByFace
extrudeEdgesByRailsToLattice
extrudeEdgesByVector
extrude_test
facemakertool2D
file_loaded
file_loaded?
fillettool2D
freehandtool2D
getOffsetPolygon
getOffsetPolygon2
getOffsetPolygon3
hatchingtool2D
helix
initialize
inputbox
isOdd
join_edges
line2cyl
linestyletool2D
linetool2D
make_pano_pm
make_selected_components_unique
paramT
points_on_circle
polygontool2D
polylineedittool2D
rectangletool2D
require_all
revolve_test
show_ruby_panel
sign
simplyContours
tellPctComplete
texttool2D
wd
wp
wpp
zplane2D -
It seems to come from cases where Classes are declared directly at top-level without being enclosed within a Module.
Fredo
PS: I don't think Namespace generates a loss of performance (on the contrary, since evrything is hashed, it might be even be faster, as in each Module there is less symbol defined so that resolution is faster)
-
A lot of us, especially in the early days followed the examples in the API etc...
Hence some of my earlier tools, like ExtendEdgesBy... are 'raw' and are still on the 'to do list' to get themselves module-ized... -
initialize
This isObject
's defaultinitialize
method, which is always private, and inherited by all objects in Ruby. It's supposed to be there. If you DO NOT define an override in your class, then Object's gets used. So do not change or remove it. (And it should not have been changed by ANY script!)
The following methods are from "Tools/sketchup.rb" and are supposed to be global methods (although I have argued that some of them belong in other modules, such as
UI
.)Could have gone in the
UI
module:
add_separator_to_menu
inputbox
(really should be replaced by a better/fixedUI.inputbox
method)
show_ruby_panel
These ARE supposed to be global, and inherited by all modules and classes (in the same way that
require
andload
is.)
Therefor the API could have "legally" put them in theKernel
module:
file_loaded
file_loaded?
require_all
And then we would not need to require 'sketchup.rb' in every file.
-
create_box
make_pano_pm
These come from the unwrapped Google/Trimble "Photo Textures" extension. You can turn it off through the Preferences dialog.
Also note, with this extension ON, the create_box Example will not work, because the Examples are also unwrapped.
-
Maybee there can be another motivation to declare methods within a small namespace : they are loaded & executed faster
-
Sandbox Tools are responsible for most of them:
@unknownuser said:
CalcTriangleProperties
CheckEntity
CountDuplicates
Equal2D
Equal2D2
FacesAreTriangles
GetAllVertices
GetCursorID
GetFaceNormal
GetFaces
GetPolyNormal
GetTransformedVertexPositions
GetVertsInWCS
In2DCircle
InPlane
IsAlreadySelected
LineFaceIntersection
NegIfEven
PointInArray
PutsTransform
RemoveNonFunctionalVerts
SegmentsCross2D
SelectAllConnected
TriangulateDelaunay
VectorScalarMult
getOffsetPolygon
getOffsetPolygon2
getOffsetPolygon3
isOdd
paramT
sign
tellPctComplete
Advertisement