Skip to content
Merged
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
70 changes: 48 additions & 22 deletions set.c
Original file line number Diff line number Diff line change
Expand Up @@ -621,16 +621,12 @@ set_inspect(VALUE set, VALUE dummy, int recur)

/*
* call-seq:
* inspect -> new_string
* inspect -> string
*
* Returns a new string containing the set entries:
* Returns a string representation of +self+:
*
* s = Set.new
* s.inspect # => "Set[]"
* s.add(1)
* s.inspect # => "Set[1]"
* s.add(2)
* s.inspect # => "Set[1, 2]"
* Set[*%w[foo bar], {foo: 0, bar: 1}].inspect
* # => "Set[\"foo\", \"bar\", {foo: 0, bar: 1}]"
*
* Related: see {Methods for Converting}[rdoc-ref:Set@Methods+for+Converting].
*/
Expand Down Expand Up @@ -1315,7 +1311,12 @@ set_i_size(VALUE set)
* call-seq:
* empty? -> true or false
*
* Returns true if the set contains no elements.
* Returns whether +self+ contains no elements:
*
* Set[].empty? # => true
* Set[0].empty? # => false
*
* Related: see {Methods for Querying}[rdoc-ref:Set@Methods+for+Querying].
*/
static VALUE
set_i_empty(VALUE set)
Expand Down Expand Up @@ -1658,10 +1659,23 @@ set_flatten_merge(VALUE set, VALUE from, VALUE hash)

/*
* call-seq:
* flatten -> set
* flatten -> new_set
*
* Returns a new set that is a copy of +self+,
* but with +self+ and its nested sets flattened;
* that is, their elements become elements of +self+:
*
* Returns a new set that is a copy of the set, flattening each
* containing set recursively.
* Set[Set[0, 1], Set[2, 3]].flatten
* # => Set[0, 1, 2, 3]
* Set[Set[0, 1], Set[Set[2, 3], Set[3, 4]]].flatten
* # => Set[0, 1, 2, 3, 4]
*
* Does not flatten nested arrays or hashes:
*
* Set[%w[foo bar]].flatten # => Set[["foo", "bar"]]
* Set[{foo: 0, bar: 1}].flatten # => Set[{foo: 0, bar: 1}]
*
* Related: see {Methods for Converting}[rdoc-ref:Set@Methods+for+Converting].
*/
static VALUE
set_i_flatten(VALUE set)
Expand All @@ -1683,10 +1697,21 @@ set_contains_set_i(st_data_t item, st_data_t arg)

/*
* call-seq:
* flatten! -> self
* flatten! -> self or nil
*
* Equivalent to Set#flatten, but replaces the receiver with the
* result in place. Returns nil if no modifications were made.
* Like #flatten, but if any changes were made
* replaces +self+ with the result and returns +self+:
*
* Set[Set[0, 1], Set[2, 3]].flatten!
* # => Set[0, 1, 2, 3]
* Set[Set[0, 1], Set[Set[2, 3], Set[3, 4]]].flatten!
* # => Set[0, 1, 2, 3, 4]
*
* Returns +nil+ if no changes were made:
*
* Set[0, 1, 2].flatten! # => nil
*
* Related: see {Methods for Assigning}[rdoc-ref:Set@Methods+for+Assigning].
*/
static VALUE
set_i_flatten_bang(VALUE set)
Expand Down Expand Up @@ -1792,15 +1817,16 @@ set_intersect_i(st_data_t key, st_data_t arg)

/*
* call-seq:
* intersect?(set) -> true or false
* intersect?(enumerable) -> true or false
*
* Returns whether +self+ and +enumerable+ have any elements in common:
*
* Returns true if the set and the given enumerable have at least one
* element in common.
* set = Set[0, 'zero', :zero]
* set.intersect?([0, 1, 2]) # => true
* set.intersect?(%w[zero one two]) # => true
* set.intersect?(Set[3]) # => false
*
* Set[1, 2, 3].intersect? Set[4, 5] #=> false
* Set[1, 2, 3].intersect? Set[3, 4] #=> true
* Set[1, 2, 3].intersect? 4..5 #=> false
* Set[1, 2, 3].intersect? [3, 4] #=> true
* Related: see {Methods for Querying}[rdoc-ref:Set@Methods+for+Querying].
*/
static VALUE
set_i_intersect(VALUE set, VALUE other)
Expand Down