summaryrefslogtreecommitdiff
path: root/object.c
diff options
context:
space:
mode:
authornaruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-04-08 03:05:15 +0000
committernaruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-04-08 03:05:15 +0000
commitae13ab24669e787a73a98a533d4bd7db8c4b49ab (patch)
tree97b8c5eb99f5237a02a60a0d044471ca64ec9803 /object.c
parent6cb682a48005f43f3f1599d6c510523de237040d (diff)
* object.c (rb_obj_ivar_set): call to_str for string only once.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40178 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'object.c')
-rw-r--r--object.c12
1 files changed, 8 insertions, 4 deletions
diff --git a/object.c b/object.c
index e2da8d5092..7c149b02b1 100644
--- a/object.c
+++ b/object.c
@@ -2189,12 +2189,16 @@ rb_obj_ivar_set(VALUE obj, VALUE iv, VALUE val)
QUOTE_ID(id));
}
}
- else if (!rb_is_instance_name(iv)) {
+ else {
+ VALUE name = rb_check_string_type(iv);
+ if (NIL_P(name)) {
+ rb_raise(rb_eTypeError, "%+"PRIsVALUE" is not a symbol or string", iv);
+ }
+ if (!rb_is_instance_name(name)) {
rb_name_error_str(iv, "`%"PRIsVALUE"' is not allowed as an instance variable name",
QUOTE(iv));
- }
- else {
- id = rb_to_id(iv);
+ }
+ id = rb_to_id(name);
}
return rb_ivar_set(obj, id, val);
}