Skip to content

Commit

Permalink
Implement Enumerable#to_set inside set.rb
Browse files Browse the repository at this point in the history
  • Loading branch information
adambeynon committed Oct 6, 2013
1 parent 006819e commit 46d23f2
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
2 changes: 2 additions & 0 deletions spec/filters/bugs/set.rb
Expand Up @@ -3,4 +3,6 @@
fails "Set#== returns true when the passed Object is a Set and self and the Object contain the same elements"
fails "Set#== does not depend on the order of nested Sets"
fails "Set#merge raises an ArgumentError when passed a non-Enumerable"

fails "Emumerable#to_set allows passing an alternate class for Set"
end
1 change: 1 addition & 0 deletions spec/rubyspecs
Expand Up @@ -227,6 +227,7 @@ library/set/member_spec
library/set/merge_spec
library/set/size_spec
library/set/to_a_spec
library/set/enumerable/to_set_spec
core/kernel/comparison_spec
core/matchdata/to_a_spec
core/range/begin_spec
Expand Down
8 changes: 7 additions & 1 deletion stdlib/set.rb
Expand Up @@ -80,4 +80,10 @@ def size
def to_a
@hash.keys
end
end
end

module Enumerable
def to_set(klass = Set, *args, &block)
klass.new(self, *args, &block)
end
end

0 comments on commit 46d23f2

Please sign in to comment.