Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions lib/set.rb
Original file line number Diff line number Diff line change
Expand Up @@ -638,11 +638,16 @@ def -(enum)
end
alias difference -

# Returns a new set containing elements common to the set and the
# given enumerable object.
# :call-seq:
# self & object -> new_set
#
# Returns a new set containing elements found both in +self+
# and in +object+, which must be an array:
#
# s = [0, 'a', :foo, 1, 'b', :bar]
# s & [0, 'b', 1, :bar] # => [0, 1, "b", :bar]
# s & [2, 'c'] # => []
#
# Set[1, 3, 5] & Set[3, 2, 1] #=> #<Set: {3, 1}>
# Set['a', 'b', 'z'] & ['a', 'b', 'c'] #=> #<Set: {"a", "b"}>
def &(enum)
n = self.class.new
if enum.is_a?(Set)
Expand Down