8000 Adding section: What's Here · ruby/set@ab81354 · GitHub
[go: up one dir, main page]

Skip to content

Commit ab81354

Browse files
committed
Adding section: What's Here
1 parent 15dcc46 commit ab81354

File tree

1 file changed

+154
-0
lines changed

1 file changed

+154
-0
lines changed

lib/set.rb

Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,160 @@
6262
#
6363
# - Akinori MUSHA <<knu@iDaemons.org>> (current maintainer)
6464
#
65+
# ## What's Here
66+
#
67+
# First, what's elsewhere. \Set includes the module Enumerable,
68+
# which provides dozens of additional methods.
69+
#
70+
# In particular, class \Set does not have many methods of its own
71+
# for fetching or for iterating.
72+
# Instead, it relies on those in \Enumerable.
73+
#
74+
# Here, class \Set provides methods that are useful for:
75+
#
76+
# - [Creating a Set](#class-Set-label-Methods+for+Creating+a+Set)
77+
# - [Set Operations](#class-Set-label-Methods+for+Set+Operations)
78+
# - [Comparing](#class-Set-label-Methods+for+Comparing)
79+
# - [Querying](#class-Set-label-Methods+for+Querying)
80+
# - [Assigning](#class-Set-label-Methods+for+Assigning)
81+
# - [Deleting](#class-Set-label-Methods+for+Deleting)
82+
# - [Converting](#class-Set-label-Methods+for+Converting)
83+
# - [Iterating](#class-Set-label-Methods+for+Iterating)
84+
# - [And more....](#class-Set-label-Other+Methods)
85+
#
86+
# ### Methods for Creating a \Set
87+
#
88+
# - ::[] -
89+
# Returns a new set containing the given objects.
90+
# - ::new -
91+
# Returns a new set containing either the given objects
92+
# (if no block given) or the return values from the called block
93+
# (if a block given).
94+
#
95+
# ### Methods for \Set Operations
96+
#
97+
# - [|](Set.html#method-i-7C) (aliased as #union and #+) -
98+
# Returns a new set containing all elements from +self+
99+
# and all elements from a given enumerable (no duplicates).
100+
# - [&](Set.html#method-i-26) (aliased as #intersection) -
101+
# Returns a new set containing all elements common to +self+
102+
# and a given enumerable.
103+
# - [-](Set.html#method-i-2D) (aliased as #difference) -
104+
# Returns a copy of +self+ with all elements
105+
# in a given enumerable removed.
106+
# - [\^](Set.html#method-i-5E) -
107+
# Returns a new set containing all elements from +self+
108+
# and a given enumerable except those common to both.
109+
#
110+
# ### Methods for Comparing
111+
#
112+
# - [<=>](Set.html#method-i-3C-3D-3E) -
113+
# Returns -1, 0, or 1 as +self+ is less than, equal to,
114+
# or greater than a given object.
115+
# - [==](Set.html#method-i-3D-3D) -
116+
# Returns whether +self+ and a given enumerable are equal,
117+
# as determined by Object#eql?.
118+
# - \#compare_by_identity? -
119+
# Returns whether the set considers only identity
120+
# when comparing elements.
121+
#
122+
# ### Methods for Querying
123+
#
124+
# - \#length (aliased as #size) -
125+
# Returns the count of elements.
126+
# - \#empty? -
127+
# Returns whether the set has no elements.
128+
# - \#include? (aliased as #member? and #===) -
129+
# Returns whether a given object is an element in the set.
130+
# - \#subset? (aliased as [<=](Set.html#method-i-3C-3D)) -
131+
# Returns whether a given object is a subset of the set.
132+
# - \#proper_subset? (aliased as [<](Set.html#method-i-3C)) -
133+
# Returns whether a given enumerable is a proper subset of the set.
134+
# - \#superset? (aliased as [<=](Set.html#method-i-3E-3D])) -
135+
# Returns whether a given enumerable is a superset of the set.
136+
# - \#proper_superset? (aliased as [>](Set.html#method-i-3E)) -
137+
# Returns whether a given enumerable is a proper superset of the set.
138+
# - \#disjoint? -
139+
# Returns +true+ if the set and a given enumerable
140+
# have no common elements, +false+ otherwise.
141+
# - \#intersect? -
142+
# Returns +true+ if the set and a given enumerable -
143+
# have any common elements, +false+ otherwise.
144+
# - \#compare_by_identity? -
145+
# Returns whether the set considers only identity
146+
# when comparing elements.
147+
#
148+
# ### Methods for Assigning
149+
#
150+
# - \#add (aliased as #<<) -
151+
# Adds a given object to the set; returns +self+.
152+
# - \#add? -
153+
# If the given object is not an element in the set,
154+
# adds it and returns +self+; otherwise, returns +nil+.
155+
# - \#merge -
156+
# Adds each given object to the set; returns +self+.
157+
# - \#replace -
158+
# Replaces the contents of the set with the contents
159+
# of a given enumerable.
160+
#
161+
# ### Methods for Deleting
162+
#
163+
# - \#clear -
164+
# Removes all elements in the set; returns +self+.
165+
# - \#delete -
166+
# Removes a given object from the set; returns +self+.
167+
# - \#delete? -
168+
# If the given object is an element in the set,
169+
# removes it and returns +self+; otherwise, returns +nil+.
170+
# - \#subtract -
171+
# Removes each given object from the set; returns +self+.
172+
# - \#delete_if - Removes elements specified by a given block.
173+
# - \#select! (aliased as #filter!) -
174+
# Removes elements not specified by a given block.
175+
# - \#keep_if -
176+
# Removes elements not specified by a given block.
177+
# - \#reject!
178+
# Removes elements specified by a given block.
179+
#
180+
# ### Methods for Converting
181+
#
182+
# - \#classify -
183+
# Returns a hash that classifies the elements,
184+
# as determined by the given block.
185+
# - \#collect! (aliased as #map!) -
186+
# Replaces each element with a block return-value.
187+
# - \#divide -
188+
# Returns a hash that classifies the elements,
189+
# as determined by the given block;
190+
# differs from #classify in that the block may accept
191+
# either one or two arguments.
192+
# - \#flatten -
193+
# Returns a new set that is a recursive flattening of +self+.
194+
# \#flatten! -
195+
# Replaces each nested set in +self+ with the elements from that set.
196+
# - \#inspect (aliased as #to_s) -
197+
# Returns a string displaying the elements.
198+
# - \#join -
199+
# Returns a string containing all elements, converted to strings
200+
# as needed, and joined by the given record separator.
201+
# - \#to_a -
202+
# Returns an array containing all set elements.
203+
# - \#to_set -
204+
# Returns +self+ if given no arguments and no block;
205+
# with a block given, returns a new set consisting of block
206+
# return values.
207+
#
208+
# ### Methods for Iterating
209+
#
210+
# - \#each -
211+
# Calls the block with each successive element; returns +self+.
212+
#
213+
# ### Other Methods
214+
#
215+
# - \#reset -
216+
# Resets the internal state; useful if an object
217+
# has been modified while an element in the set.
218+
#
65219
class Set
66220
include Enumerable
67221

0 commit comments

Comments
 (0)
0