• Login
sketchucation logo sketchucation
  • Login
⚠️ Libfredo 15.4b | Minor release with bugfixes and improvements Update

Pollution Private methods of Class

Scheduled Pinned Locked Moved Developers' Forum
9 Posts 5 Posters 239 Views 5 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.
  • F Offline
    fredo6
    last edited by 8 Jul 2012, 14:22

    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.

    1 Reply Last reply Reply Quote 0
    • Dan RathbunD Offline
      Dan Rathbun
      last edited by 8 Jul 2012, 17:19

      @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 of Object, 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

      I'm not here much anymore.

      1 Reply Last reply Reply Quote 0
      • F Offline
        fredo6
        last edited by 8 Jul 2012, 17:52

        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 machine

        CalcTriangleProperties
        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

        1 Reply Last reply Reply Quote 0
        • F Offline
          fredo6
          last edited by 8 Jul 2012, 21:23

          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)

          1 Reply Last reply Reply Quote 0
          • TIGT Offline
            TIG Moderator
            last edited by 8 Jul 2012, 21:58

            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... 😒

            TIG

            1 Reply Last reply Reply Quote 0
            • Dan RathbunD Offline
              Dan Rathbun
              last edited by 8 Jul 2012, 22:18

              initialize
              This is Object's default initialize 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/fixed UI.inputbox method)
              show_ruby_panel

              These ARE supposed to be global, and inherited by all modules and classes (in the same way that require and load is.)
              Therefor the API could have "legally" put them in the Kernel module:
              file_loaded
              file_loaded?
              require_all

              And then we would not need to require 'sketchup.rb' in every file.

              I'm not here much anymore.

              1 Reply Last reply Reply Quote 0
              • Dan RathbunD Offline
                Dan Rathbun
                last edited by 8 Jul 2012, 22:25

                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.

                I'm not here much anymore.

                1 Reply Last reply Reply Quote 0
                • P Offline
                  pgarmyn
                  last edited by 9 Jul 2012, 06:05

                  Maybee there can be another motivation to declare methods within a small namespace : they are loaded & executed faster

                  1 Reply Last reply Reply Quote 0
                  • J Offline
                    Jim
                    last edited by 9 Jul 2012, 08:11

                    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

                    Hi

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

                    Advertisement