aboutsummaryrefslogtreecommitdiffstats
path: root/variable.c
diff options
context:
space:
mode:
authorMarc-Andre Lafortune <github@marc-andre.ca>2020-09-01 21:22:20 -0400
committerMarc-André Lafortune <github@marc-andre.ca>2020-09-02 00:05:14 -0400
commit5e16857315bf55307c5fc887ca6f03bfa0630a93 (patch)
treed42bcc39f4cdfb958d620f3d1389f2aa677b77cb /variable.c
parent11922b5e030808b16fd2c604637e046b2d01b0f0 (diff)
downloadruby-5e16857315bf55307c5fc887ca6f03bfa0630a93.tar.gz
Fix constant names set using const_set on a singleton class
Fixes [Bug #14895]
Diffstat (limited to 'variable.c')
-rw-r--r--variable.c17
1 files changed, 9 insertions, 8 deletions
diff --git a/variable.c b/variable.c
index 26928ca0bc..3c3b689889 100644
--- a/variable.c
+++ b/variable.c
@@ -2854,14 +2854,15 @@ rb_const_set(VALUE klass, ID id, VALUE val)
else {
int parental_path_permanent;
VALUE parental_path = classname(klass, &parental_path_permanent);
- if (!NIL_P(parental_path)) {
- if (parental_path_permanent && !val_path_permanent) {
- set_namespace_path(val, build_const_path(parental_path, id));
- }
- else if (!parental_path_permanent && NIL_P(val_path)) {
- rb_ivar_set(val, tmp_classpath, build_const_path(parental_path, id));
- }
- }
+ if (NIL_P(parental_path)) {
+ parental_path = rb_funcall(klass, rb_intern("to_s"), 0);
+ }
+ if (parental_path_permanent && !val_path_permanent) {
+ set_namespace_path(val, build_const_path(parental_path, id));
+ }
+ else if (!parental_path_permanent && NIL_P(val_path)) {
+ rb_ivar_set(val, tmp_classpath, build_const_path(parental_path, id));
+ }
}
}
}