Sketchup::Set vs Set

When do you use Sketchup::Set instead of the ruby Set?

This is a good one for @thomthom :slight_smile:

Don’t use Sketchup::Set - we should have marked it as deprecated. The Ruby Set class is much faster and much better implemented. It was kept around in the Sketchup module simply for backwards compatibility with older projects.

1 Like

Thanks Thom,

I was looking for a reason why I should use Sketchup::Set instead of the ruby Set. I thought there must be a reason for its existence, but there is no. Ok thats clear to me.

There are some differences in the names of methods.

I did a write up on it somewhere (probably SketchUcation.)

Sorry to revive this old thread. I have the same question as the OP. If I look at the API docs (link below) - its a bit confusing and the example code throws an error.

In the first line of the link, it states in 2014 it was changed from Set to SketchUp::Set and next it states we should use the Set class because SketchUp::Set is deprecated?!

If you try the example code from that page
set = Set.new
set.insert(‘Hello’)

the last line throws an error…
Confused - where can I find the correct information on using a Set in SketchUp?

This discussion is talking about require 'set' versus classes introduced by SketchUp (Sketchup, Geom, UI, Set which later was moved to Sketchup::Set).

SketchUp 2014 introduced a new version of Ruby and decided to ship also Ruby’s standard library (all what you require before using). This would have caused a name clash if not moving SketchUp’s own Set. On the other side, it became way easier to use the (better) implementation of Set from Ruby, because developers would not have to download it elsewhere and package it with their plugin.

As Dan mentioned, methods are named differently, and the deprecation message means not to use this page, but the documentation of Ruby’s Set. So the example becomes:

require 'set' # At the beginning of the file
set = Set.new
set.add('Hello')
set.include?('你好')
2 Likes

Thanks for the clarification. I think I need more coffee today…

SketchUp 2014+
http://ruby-doc.org/stdlib-2.0.0/libdoc/set/rdoc/index.html

SketchUp 2017+
http://ruby-doc.org/stdlib-2.2.4/libdoc/set/rdoc/index.html

1 Like

Thanks for the links Dan.