• Login
sketchucation logo sketchucation
  • Login
ℹ️ GoFundMe | Our friend Gus Robatto needs some help in a challenging time Learn More

SketchUp Arrays & Enumerable

Scheduled Pinned Locked Moved Developers' Forum
7 Posts 3 Posters 1.2k Views
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 9 Aug 2008, 14:46

    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
    • T Offline
      tbd
      last edited by 9 Aug 2008, 17:12

      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 9 Aug 2008, 17:26

        @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
        • T Offline
          tbd
          last edited by 9 Aug 2008, 17:40

          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 28 Aug 2008, 10:14

            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 28 Aug 2008, 10:32

              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 29 Aug 2008, 16:42

                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