diff options
-rw-r--r-- | spec/ruby/core/module/set_temporary_name_spec.rb | 19 | ||||
-rw-r--r-- | test/ruby/test_module.rb | 9 | ||||
-rw-r--r-- | variable.c | 82 |
3 files changed, 101 insertions, 9 deletions
@@ -108,13 +108,18 @@ ruby_version_is "3.3" do m.name.should == "fake_name_2" end - it "does not affect a name of a module nested into an anonymous module with a temporary name" do - m = Module.new - m::N = Module.new - m::N.name.should =~ /\A#<Module:0x\h+>::N\z/ - - m.set_temporary_name("foo") - m::N.name.should =~ /\A#<Module:0x\h+>::N\z/ end it "keeps temporary name when assigned in an anonymous module" do @@ -3378,13 +3378,22 @@ class TestModule < Test::Unit::TestCase m::N.set_temporary_name(nil) assert_nil(m::N.name) m.set_temporary_name(name = "fake_name") name.upcase! assert_equal("fake_name", m.name) assert_raise(FrozenError) {m.name.upcase!} m.set_temporary_name(nil) assert_nil m.name assert_raise_with_message(ArgumentError, "empty class/module name") do m.set_temporary_name("") @@ -166,6 +166,80 @@ is_constant_path(VALUE name) return true; } /* * call-seq: * mod.set_temporary_name(string) -> self @@ -224,7 +298,9 @@ rb_mod_set_temporary_name(VALUE mod, VALUE name) if (NIL_P(name)) { // Set the temporary classpath to NULL (anonymous): - RCLASS_SET_CLASSPATH(mod, 0, FALSE); } else { // Ensure the name is a string: @@ -241,7 +317,9 @@ rb_mod_set_temporary_name(VALUE mod, VALUE name) name = rb_str_new_frozen(name); // Set the temporary classpath to the given name: - RCLASS_SET_CLASSPATH(mod, name, FALSE); } return mod; |