sketchucation logo sketchucation
    • Login
    Oops, your profile's looking a bit empty! To help us tailor your experience, please fill in key details like your SketchUp version, skill level, operating system, and more. Update and save your info on your profile page today!
    šŸ«› Lightbeans Update | Metallic and Roughness auto-applied in SketchUp 2025+ Download

    SketchUp Arrays & Enumerable

    Scheduled Pinned Locked Moved Developers' Forum
    7 Posts 3 Posters 1.3k 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.
    • J Offline
      Jim
      last edited by GƔbor

      If I type the following in the Ruby Console:

      
      Array.ancestors
      [Array, Enumerable, Object, Kernel]
      
      

      it shows Enumerable is mixed in Array. Is there some reason I can use some methods from Enumerable such as each_with_index, but not each_slice?

      Hi

      1 Reply Last reply Reply Quote 0
      • tbdT Offline
        tbd
        last edited by

        you need to require 'enumerator' to be able to use each_slice

        SketchUp Ruby Consultant | Podium 1.x developer
        http://plugins.ro

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

          @unknownuser said:

          you need to require 'enumerator' to be able to use each_slice

          Why does each_with_index work, while each_slice does not? Both are from Enumerable.

          It seems like only parts of Enumerable are included. Maybe the version of Ruby compiled with SketchUp did not have each_slice at the time.

          Hi

          1 Reply Last reply Reply Quote 0
          • tbdT Offline
            tbd
            last edited by

            if you check the enum.c (Ruby C code for Enumerable class) you will see that only each_with_index is there and each_slice
            is part of ext/enumerator.c šŸ˜‰

            SketchUp Ruby Consultant | Podium 1.x developer
            http://plugins.ro

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

              So here's a list of all the instance methods of an Array in a SketchUp/Ruby array. It has some elements of a regular Ruby Array, some methods of Enumerable, and of course the SketchUp specific methods.

              ["&", "*", "+", "-", "<<", "[]", "[]=", "assoc", "at", "clear", "collect", "collect!", "compact", "compact!", "concat", "cross", "delete", "delete_at", "delete_if", "distance", "distance_to_line", "distance_to_plane", "dot", "each", "each_index", "empty?", "fetch", "fill", "first", "flatten", "flatten!", "index", "indexes", "indices", "insert", "join", "last", "length", "map", "map!", "nitems", "normalize", "normalize!", "offset", "offset!", "on_line?", "on_plane?", "pack", "pop", "project_to_line", "project_to_plane", "push", "rassoc", "reject", "reject!", "replace", "reverse", "reverse!", "reverse_each", "rindex", "select", "shift", "size", "slice", "slice!", "sort", "sort!", "to_ary", "transform", "transform!", "transpose", "uniq", "uniq!", "unshift", "values_at", "vector_to", "x", "x=", "y", "y=", "z", "z=", "zip", "|"]
              

              I don't think it's complete because I still I missed "each_with_index"

              Hi

              1 Reply Last reply Reply Quote 0
              • A Offline
                azuby
                last edited by

                Maybe it depends on the Sketchup version you are using? Mine is 6.4.112 and the result of "puts Array.new.methods.sort" is:

                &
                *
                +
                -
                <<
                <=>
                ==
                ===
                =~
                []
                []=
                __id__
                __send__
                all?
                any?
                assoc
                at
                class
                clear
                clone
                collect
                collect!
                compact
                compact!
                concat
                cross
                delete
                delete_at
                delete_if
                detect
                display
                distance
                distance_to_line
                distance_to_plane
                dot
                dup
                each
                each_index
                each_with_index
                empty?
                entries
                eql?
                equal?
                extend
                fetch
                fill
                find
                find_all
                first
                flatten
                flatten!
                freeze
                frozen?
                get_binding
                grep
                hash
                id
                include?
                index
                indexes
                indices
                inject
                insert
                inspect
                instance_eval
                instance_of?
                instance_variable_get
                instance_variable_set
                instance_variables
                is_a?
                join
                kind_of?
                last
                length
                map
                map!
                max
                member?
                method
                methods
                min
                nil?
                nitems
                normalize
                normalize!
                object_id
                offset
                offset!
                on_line?
                on_plane?
                pack
                partition
                pop
                private_methods
                project_to_line
                project_to_plane
                protected_methods
                public_methods
                push
                rassoc
                reject
                reject!
                replace
                respond_to?
                reverse
                reverse!
                reverse_each
                rindex
                select
                send
                shift
                singleton_methods
                size
                slice
                slice!
                sort
                sort!
                sort_by
                taint
                tainted?
                to_a
                to_ary
                to_b
                to_s
                transform
                transform!
                transpose
                type
                uniq
                uniq!
                unshift
                untaint
                values_at
                vector_to
                x
                x=
                y
                y=
                z
                z=
                zip
                |
                

                *error initus :: Blocks | CurrentDate | d/Code | extensionmanager | FFlipper | HideEdges | MeasuredArea | ModelHistory | PluginsHelp | PronButton | SAWSO | SCP | SU²CATT

                Bad English? PM me, correct me. :smile:**

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

                  Ah, I used Array.instance_methods but I see that it requires an agument of "true" to get the inherited and mix-in methods also. ( 98 methods )

                  
                  (Array.instance_methods(true) - Object.methods).sort
                  ["&", "*", "+", "-", "<<", "[]", "[]=", "all?", "any?", "assoc", "at", "clear", "collect", "collect!", "compact", "compact!", "concat", "cross", "delete", "delete_at", "delete_if", "detect", "distance", "distance_to_line", "distance_to_plane", "dot", "each", "each_index", "each_with_index", "empty?", "entries", "fetch", "fill", "find", "find_all", "first", "flatten", "flatten!", "grep", "index", "indexes", "indices", "inject", "insert", "join", "last", "length", "map", "map!", "max", "member?", "min", "nitems", "normalize", "normalize!", "offset", "offset!", "on_line?", "on_plane?", "pack", "partition", "pop", "project_to_line", "project_to_plane", "push", "rassoc", "reject", "reject!", "replace", "reverse", "reverse!", "reverse_each", "rindex", "select", "shift", "size", "slice", "slice!", "sort", "sort!", "sort_by", "to_ary", "transform", "transform!", "transpose", "uniq", "uniq!", "unshift", "values_at", "vector_to", "x", "x=", "y", "y=", "z", "z=", "zip", "|"]
                  
                  
                  

                  Hi

                  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