Hatena::ブログ(Diary)

西尾泰和のはてなダイアリー

2010-08-15

Rubyいじり

Rubyをいじってるナウ

--- object.c	(revision 28759)
+++ object.c	(working copy)
@@ -1542,7 +1542,7 @@
 rb_class_new_instance(int argc, VALUE *argv, VALUE klass)
 {
     VALUE obj;

+    printf("rb_class_new_instance %s\n", rb_class2name(klass));
     obj = rb_obj_alloc(klass);
     rb_obj_call_init(obj, argc, argv);
irb(main):001:0> 1
rb_class_new_instance RubyToken::TkINTEGER
rb_class_new_instance RubyToken::TkNL
=> 1
irb(main):002:0> x = 1 + "hoge"
rb_class_new_instance RubyToken::TkIDENTIFIER
rb_class_new_instance RubyToken::TkSPACE
rb_class_new_instance RubyToken::TkASSIGN
rb_class_new_instance RubyToken::TkSPACE
rb_class_new_instance RubyToken::TkINTEGER
rb_class_new_instance RubyToken::TkSPACE
rb_class_new_instance RubyToken::TkPLUS
rb_class_new_instance RubyToken::TkSPACE
rb_class_new_instance RubyToken::TkSTRING
rb_class_new_instance RubyToken::TkNL
rb_class_new_instance NoMethodError
rb_class_new_instance TypeError
TypeError: String can't be coerced into Fixnum
	from (irb):2:in `+'
	from (irb):2
	from bin/irb:12:in `<main>'

面白いな。しかしやりたかったのは整数や文字列のオブジェクト生成の表示なのだが。