From: "saturnflyer (Jim Gay)" Date: 2013-11-07T02:36:46+09:00 Subject: [ruby-core:58206] [CommonRuby - Feature #8626] Add a Set coercion method to the standard lib: Set(possible_set) Issue #8626 has been updated by saturnflyer (Jim Gay). This has been merged into ruby trunk in https://github.com/ruby/ruby/commit/ad78cf4ea8613c7e1790c5e3a2718a35fe32115f ---------------------------------------- Feature #8626: Add a Set coercion method to the standard lib: Set(possible_set) https://bugs.ruby-lang.org/issues/8626#change-42787 Author: saturnflyer (Jim Gay) Status: Open Priority: Normal Assignee: Category: Target version: =begin I'd like to be able to take an object that may already be a Set (or not) and ensure that it is one For example: set1 = Set.new set2 = Set(set1) set3 = Set(nil) assert set1.equal?(set2) assert_instance_of(Set, set3) This is different from the behavior of Set.new in that it will return the same set rather than creating a new one set1 = Set.new set2 = Set.new(set1) # <--- completely new object in memory set2 = Set(set1) # <--- same object from memory My thoughts about the implementation are simple: def Set(possible_set) possible_set.is_a?(Set) ? possible_set : Set.new(possible_set) end I'm not sure if there are edge cases to unexpected behavior that I haven't thought of and I'm wondering if it ought to have a Set.try_convert as well =end -- http://bugs.ruby-lang.org/