mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* 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
This commit is contained in:
parent
e1aec4aed8
commit
4503c8daeb
2 changed files with 32 additions and 7 deletions
|
@ -1,3 +1,11 @@
|
||||||
|
Tue Mar 20 11:09:00 2007 Akinori MUSHA <knu@iDaemons.org>
|
||||||
|
|
||||||
|
* 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].
|
||||||
|
|
||||||
Tue Mar 20 09:13:10 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
Tue Mar 20 09:13:10 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
* process.c (rb_fork): flush stdouts always before fork(2).
|
* process.c (rb_fork): flush stdouts always before fork(2).
|
||||||
|
|
31
lib/set.rb
31
lib/set.rb
|
@ -28,14 +28,13 @@
|
||||||
# This is a hybrid of Array's intuitive inter-operation facilities and
|
# This is a hybrid of Array's intuitive inter-operation facilities and
|
||||||
# Hash's fast lookup.
|
# 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
|
# The equality of each couple of elements is determined according to
|
||||||
# Object#eql? and Object#hash, since Set uses Hash as storage.
|
# 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
|
# Set is easy to use with Enumerable objects (implementing +each+).
|
||||||
# for convenience.
|
# 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
|
# == Example
|
||||||
#
|
#
|
||||||
|
@ -78,6 +77,24 @@ class Set
|
||||||
@hash = orig.instance_eval{@hash}.dup
|
@hash = orig.instance_eval{@hash}.dup
|
||||||
end
|
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.
|
# Returns the number of elements.
|
||||||
def size
|
def size
|
||||||
@hash.size
|
@hash.size
|
||||||
|
@ -190,7 +207,7 @@ class Set
|
||||||
end
|
end
|
||||||
|
|
||||||
# Adds the given object to the set and returns self. Use +merge+ to
|
# 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)
|
def add(o)
|
||||||
@hash[o] = true
|
@hash[o] = true
|
||||||
self
|
self
|
||||||
|
@ -208,7 +225,7 @@ class Set
|
||||||
end
|
end
|
||||||
|
|
||||||
# Deletes the given object from the set and returns self. Use +subtract+ to
|
# 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)
|
def delete(o)
|
||||||
@hash.delete(o)
|
@hash.delete(o)
|
||||||
self
|
self
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue