Commit 970dbc43

970dbc43105eMerged

Yukihiro "Matz" Matsumoto <[email protected]> · 5 months ago · 2 files · ~2 modified

Description

Add x.class -> class-name string; p x.class prints bare

.class on a known builtin/object receiver yields its class name as a string (Integer/Float/String/Symbol/Range/Time/NilClass/Array/Hash/ TrueClass/FalseClass/). Since the result models a Class (not a String), p x.class prints the name without quotes.

Co-Authored-By: Claude Opus 4.8 (1M context) [email protected]

Details

Commit
970dbc43105e
Parent
cb9e3b2a1908

src/analyze.cmodifiedView file

@@ -51,6 +51,13 @@
5151 !strcmp(name, "dup") || !strcmp(name, "clone")))
5252 return rt;
5353
54+ /* x.class -> a class-name string (for known builtin/object receivers) */
55+ if (recv >= 0 && argc == 0 && !strcmp(name, "class") &&
56+ (ty_is_numeric(rt) || rt == TY_STRING || rt == TY_SYMBOL || rt == TY_BOOL ||
57+ rt == TY_RANGE || rt == TY_TIME || rt == TY_NIL ||
58+ ty_is_array(rt) || ty_is_hash(rt) || ty_is_object(rt)))
59+ return TY_STRING;
60+
5461 /* Class.new(...) -> an instance of that class; built-in .new constructors */
5562 if (recv >= 0 && !strcmp(name, "new")) {
5663 const char *rty = nt_type(nt, recv);