@@ -295,12 +295,18 @@ static VALUE _rb_js_obj_typeof(VALUE obj) {
295
295
296
296
/*
297
297
* call-seq:
298
- * inspect -> string
298
+ * to_s -> string
299
299
*
300
300
* Returns a printable version of +self+:
301
- * p JS.global # => [object global]
301
+ * JS.eval("return 'str'").to_s # => "str"
302
+ * JS.eval("return true").to_s # => "true"
303
+ * JS.eval("return 1").to_s # => "1"
304
+ * JS.eval("return null").to_s # => "null"
305
+ * JS.global.inspect # => "[object global]"
306
+ *
307
+ * JS::Object#inspect is an alias for JS::Object#to_s.
302
308
*/
303
- static VALUE _rb_js_obj_inspect (VALUE obj ) {
309
+ static VALUE _rb_js_obj_to_s (VALUE obj ) {
304
310
struct jsvalue * p = check_jsvalue (obj );
305
311
rb_js_abi_host_string_t ret0 ;
306
312
rb_js_abi_host_js_value_to_string (p -> abi , & ret0 );
@@ -415,8 +421,8 @@ void Init_js() {
415
421
rb_define_method (rb_cJS_Object , "__export_to_js" , _rb_js_export_to_js , 0 );
416
422
rb_define_singleton_method (rb_cJS_Object , "__import_from_js" ,
417
423
_rb_js_import_from_js , 0 );
418
- rb_define_method (rb_cJS_Object , "inspect " , _rb_js_obj_inspect , 0 );
419
- rb_define_method (rb_cJS_Object , "to_s " , _rb_js_obj_inspect , 0 );
424
+ rb_define_method (rb_cJS_Object , "to_s " , _rb_js_obj_to_s , 0 );
425
+ rb_define_alias (rb_cJS_Object , "inspect " , "to_s" );
420
426
rb_define_singleton_method (rb_cJS_Object , "wrap" , _rb_js_obj_wrap , 1 );
421
427
422
428
rb_define_method (rb_cInteger , "to_js" , _rb_js_integer_to_js , 0 );
0 commit comments