aboutsummaryrefslogtreecommitdiffstats
path: root/lib/set.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/set.rb')
-rw-r--r--lib/set.rb10
1 files changed, 10 insertions, 0 deletions
diff --git a/lib/set.rb b/lib/set.rb
index a9aa7e7936..47fcc3efc7 100644
--- a/lib/set.rb
+++ b/lib/set.rb
@@ -148,6 +148,16 @@ class Set
@hash.keys
end
+ # Returns self if no arguments are given. Otherwise, converts the
+ # set to another with klass.new(self, *args, &block).
+ #
+ # In subclasses, returns klass.new(self, *args, &block) unless
+ # overridden.
+ def to_set(klass = Set, *args, &block)
+ return self if instance_of?(Set) && klass == Set && block.nil? && args.empty?
+ klass.new(self, *args, &block)
+ end
+
def flatten_merge(set, seen = Set.new) # :nodoc:
set.each { |e|
if e.is_a?(Set)