зеркало из https://github.com/github/ruby.git
Implement Set#clone. [Fixes GH-661]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47083 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
Родитель
4d5fceb086
Коммит
3766aa4cc5
|
@ -1,3 +1,10 @@
|
||||||
|
Wed Aug 6 19:09:27 2014 Akinori MUSHA <knu@iDaemons.org>
|
||||||
|
|
||||||
|
* lib/set.rb (Set): Implement Set#clone by splitting
|
||||||
|
initialize_copy into initialize_dup and initialize_clone.
|
||||||
|
Submitted by yui-knk. [Fixes GH-661]
|
||||||
|
https://github.com/ruby/ruby/pull/661
|
||||||
|
|
||||||
Wed Aug 6 18:42:58 2014 Masaki Suketa <masaki.suketa@nifty.ne.jp>
|
Wed Aug 6 18:42:58 2014 Masaki Suketa <masaki.suketa@nifty.ne.jp>
|
||||||
|
|
||||||
* ext/win32ole/win32ole.c: separate src of WIN32OLERuntimeError
|
* ext/win32ole/win32ole.c: separate src of WIN32OLERuntimeError
|
||||||
|
|
11
lib/set.rb
11
lib/set.rb
|
@ -100,11 +100,18 @@ class Set
|
||||||
end
|
end
|
||||||
private :do_with_enum
|
private :do_with_enum
|
||||||
|
|
||||||
# Copy internal hash.
|
# Dup internal hash.
|
||||||
def initialize_copy(orig)
|
def initialize_dup(orig)
|
||||||
|
super
|
||||||
@hash = orig.instance_variable_get(:@hash).dup
|
@hash = orig.instance_variable_get(:@hash).dup
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Clone internal hash.
|
||||||
|
def initialize_clone(orig)
|
||||||
|
super
|
||||||
|
@hash = orig.instance_variable_get(:@hash).clone
|
||||||
|
end
|
||||||
|
|
||||||
def freeze # :nodoc:
|
def freeze # :nodoc:
|
||||||
@hash.freeze
|
@hash.freeze
|
||||||
super
|
super
|
||||||
|
|
|
@ -585,6 +585,28 @@ class TC_Set < Test::Unit::TestCase
|
||||||
assert_equal 4, set.size
|
assert_equal 4, set.size
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_freeze_dup
|
||||||
|
set1 = Set[1,2,3]
|
||||||
|
set1.freeze
|
||||||
|
set2 = set1.dup
|
||||||
|
|
||||||
|
assert_not_predicate set2, :frozen?
|
||||||
|
assert_nothing_raised {
|
||||||
|
set2.add 4
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_freeze_clone
|
||||||
|
set1 = Set[1,2,3]
|
||||||
|
set1.freeze
|
||||||
|
set2 = set1.clone
|
||||||
|
|
||||||
|
assert_predicate set2, :frozen?
|
||||||
|
assert_raise(RuntimeError) {
|
||||||
|
set2.add 5
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
def test_inspect
|
def test_inspect
|
||||||
set1 = Set[1]
|
set1 = Set[1]
|
||||||
|
|
||||||
|
|
Загрузка…
Ссылка в новой задаче