summaryrefslogtreecommitdiff
path: root/lib/set.rb
diff options
context:
space:
mode:
authorknu <knu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2007-03-20 02:09:10 +0000
committerknu <knu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2007-03-20 02:09:10 +0000
commit4503c8daebd2b8c572a313117b5d9c50e824ab14 (patch)
treee76aa4c8890a212b791e61df4b819caf38142a15 /lib/set.rb
parente1aec4aed8e745c41ab36ad8914285f011cd8b4f (diff)
* lib/set.rb: Revise rdoc.
* lib/set.rb (Set#freeze, Set#taint, Set#untaint): Implement Set#freeze, Set#taint, and Set#untaint; requested by: Dan Hutchings <dan AT moltoagitato.com> in [ruby-bugs:PR#9359]. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12104 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/set.rb')
-rw-r--r--lib/set.rb31
1 files changed, 24 insertions, 7 deletions
diff --git a/lib/set.rb b/lib/set.rb
index 15f5cee..12e9486 100644
--- a/lib/set.rb
+++ b/lib/set.rb
@@ -28,14 +28,13 @@
# This is a hybrid of Array's intuitive inter-operation facilities and
# Hash's fast lookup.
#
-# Several methods accept any Enumerable object (implementing +each+)
-# for greater flexibility: new, replace, merge, subtract, |, &, -, ^.
-#
# The equality of each couple of elements is determined according to
# Object#eql? and Object#hash, since Set uses Hash as storage.
#
-# Finally, if you are using class Set, you can also use Enumerable#to_set
-# for convenience.
+# Set is easy to use with Enumerable objects (implementing +each+).
+# Most of the initializer methods and binary operators accept generic
+# Enumerable objects besides sets and arrays. An Enumerable object
+# can be converted to Set using the +to_set+ method.
#
# == Example
#
@@ -78,6 +77,24 @@ class Set
@hash = orig.instance_eval{@hash}.dup
end
+ def freeze # :nodoc:
+ super
+ @hash.freeze
+ self
+ end
+
+ def taint # :nodoc:
+ super
+ @hash.taint
+ self
+ end
+
+ def untaint # :nodoc:
+ super
+ @hash.untaint
+ self
+ end
+
# Returns the number of elements.
def size
@hash.size
@@ -190,7 +207,7 @@ class Set
end
# Adds the given object to the set and returns self. Use +merge+ to
- # add several elements at once.
+ # add many elements at once.
def add(o)
@hash[o] = true
self
@@ -208,7 +225,7 @@ class Set
end
# Deletes the given object from the set and returns self. Use +subtract+ to
- # delete several items at once.
+ # delete many items at once.
def delete(o)
@hash.delete(o)
self