[#37248] [Feature:1.9] Enumerator#inspect — "Yusuke ENDOH" <mame@...>
遠藤です。
At Tue, 2 Dec 2008 23:59:52 +0900,
まつもと ゆきひろです
こんにちは、なかむら(う)です。
At Wed, 3 Dec 2008 18:39:59 +0900,
[#37265] [Feature #819] Caching Symbol#to_proc — Shumpei Akai <redmine@...>
Feature #819: Caching Symbol#to_proc
[#37275] [Bug #821] uninitialized constant Test::Unit::AutoRunner — Naohisa Goto <redmine@...>
Bug #821: uninitialized constant Test::Unit::AutoRunner
In article <4937d5c0586c_87b76ae0c6417f@redmine.ruby-lang.org>,
[#37278] invalid byte sequence by pack format 'A' or 'a' — "Yugui (Yuki Sonoda)" <yugui@...>
Yuguiです。
[#37295] [BUG:trunk] Encoding in which Array#pack returns when the last format is 'u', 'M', 'm' — "Yugui (Yuki Sonoda)" <yugui@...>
Yuguiです。
まつもと ゆきひろです
[#37337] [Feature #841] Object#self — "rubikitch ." <redmine@...>
Feature #841: Object#self
まつもと ゆきひろです
こんにちは、なかむら(う)です。
[#37357] Math and NaN — Tadayoshi Funaba <tadf@...>
Math.sin に NaN を与えてもそのまま NaN が返ってきますが、Math.sqrt はエ
まつもと ゆきひろです
> |Math.sin に NaN を与えてもそのまま NaN が返ってきますが、Math.sqrt はエ
[#37370] IA-64とx64でBigDecimalの割り算の計算結果がおかしい — TAKANO Mitsuhiro <tak@...32.tk>
-----BEGIN PGP SIGNED MESSAGE-----
[#37378] Ruby開発ミーティングログ — SASADA Koichi <ko1@...>
ささだです.
こんにちは、なかむら(う)です。
こんにちは、なかむら(う)です。
[#37384] [Bug #853] Rake のテストが無い — okkez _ <redmine@...>
Bug #853: Rake のテストが無い
[#37390] [BUG:trunk] r20625 dumps core and many strings associated with wrong encoding — "Yugui (Yuki Sonoda)" <yugui@...>
Yuguiです。
Yugui (Yuki Sonoda) さんは書きました:
[#37392] [1.9:Feature] faster bignum multiplication by karatsuba method — "Yusuke ENDOH" <mame@...>
遠藤です。
[#37427] Re: [ruby-core:20448] [Bug #727] Signal(CLD) seems not to work on OS X — "Yugui (Yuki Sonoda)" <yugui@...>
Yuguiです。
[#37455] Re: [ruby-cvs:27996] Ruby:r20778 (trunk): * common.mk (complex.$(OBJEXT), rational.$(OBJEXT)): Properly add — Nobuyoshi Nakada <nobu@...>
なかだです。
At Tue, 16 Dec 2008 15:14:40 +0900,
[#37458] [Bug #891] MiniTest::Assertions#assert_instance_of should use Object#instance_of? — okkez _ <redmine@...>
Bug #891: MiniTest::Assertions#assert_instance_of should use Object#instance_of?
[#37483] (was Re: [ruby-cvs:28066]) — "Akinori MUSHA" <knu@...>
At Wed, 17 Dec 2008 19:57:17 +0900 (JST),
(2008/12/17 20:25), Akinori MUSHA wrote:
At Thu, 18 Dec 2008 00:56:00 +0900,
[#37490] minitest/spec, minitest/mock を標準添付から外しませんか? — okkez <okkez000@...>
okkez です。
[#37496] when to use default_internal — "Yugui (Yuki Sonoda)" <yugui@...>
Yuguiです。
[#37505] Re: [ruby-cvs:28084] Ruby:r20866 (trunk): * error.c (exc_equal): duck typing equal to make it transitive. — "Yugui (Yuki Sonoda)" <yugui@...>
Yuguiです。
[#37513] Current status of 1.9.1 RC1's issues — "Yugui (Yuki Sonoda)" <yugui@...>
Hi, folks
咳といいます。
Yuguiです
咳といいます。
On 12/21/08 11:22 PM, Masatoshi SEKI wrote:
咳といいます。
Yuguiです。
Yuguiです。
[#37525] [Bug #914] Integer#upto(NaN) — tadayoshi funaba <redmine@...>
Bug #914: Integer#upto(NaN)
[#37537] [Bug #913] mathn した場合、sqrt(NaN) が複素数になる — Yuki Sonoda <redmine@...>
チケット #913 が更新されました。 (by Yuki Sonoda)
[#37555] [Bug #919] tool/file2lastrev.rbでエラー — Tadashi Saito <redmine@...>
Bug #919: tool/file2lastrev.rbでエラー
[#37560] fail to complie ext pty in cygwin — Masaki Suketa <masaki.suketa@...>
助田です。
[#37572] [Bug:1.9] `initialize_copy': wrong argument type #<Class:0x825d23c> (expected Data) (TypeError) — Tanaka Akira <akr@...>
以下のプログラムで、
まつもと ゆきひろです
なかだです。
まつもと ゆきひろです
[#37576] [BUG:trunk] encoding for stdio's — "Yugui (Yuki Sonoda)" <yugui@...>
Yuguiです。
[#37591] [BUG:trunk] [m17n] TestCSVFeatures fails because of r20905 — "Yugui (Yuki Sonoda)" <yugui@...>
Yuguiです。
[#37646] [Bug #943] Segmentation fault (cygwin) — Martin Dürst <redmine@...>
Bug #943: Segmentation fault (cygwin)
[ruby-dev:37263] Re: [Feature:1.9] Enumerator#inspect
At Wed, 3 Dec 2008 18:39:59 +0900,
U.Nakamura wrote:
> In message "[ruby-dev:37261] Re: [Feature:1.9] Enumerator#inspect"
> on Dec.03,2008 18:17:53, <matz@ruby-lang.org> wrote:
> > |> Enumerator の中身をわかりやすく表示してくれる Enumerator#inspect を
> > |> 提供すると便利だと思います。例えばこんな感じ。
> > |>
> > |> $ ruby19 -e 'g = (1..1000).each; p g'
> > |> #<Enumerator:[1, 2, 3, ...(snipped)]>
> > |>
> > |> 現状は #<Enumerator:0x8269654> とかなので、デバッグには不便です。
> > |
> > | inspect で実際に回してしまうのは(中身を見るための)副作用として
> > |大きすぎ、適切ではない気がします。
> >
> > そうですねえ。IOのように再開可能でないEnumerableもありますし
> > ねえ。私もあまり賛成できません。わかりやすくするというアイディ
> > アには反対ではないんですが。
> >
> > Enumeratorの中に最初の3要素を取っておくとかは、たぶんやりすぎ
> > でしょうねえ。
>
> 実現可能かどうかは考慮してないんですが、実際の中身よりもその
> Enumeratorオブジェクトがどこから出てきたのかがわかる方が嬉し
> いような気がします。
> 上記の例だと、例えば
> #<Enumerator:Range#each>
> とか。
まあ、デバッグ用だから見せてしまってもいいかもしれませんね。
(1..100).each_cons(2) => "#<Enumerator: 1..100:each_cons(2)>"
という感じでどうでしょうか。(下に添付)
> でも、どんな出方が嬉しいかは、デバッグのやり方によるんでしょ
> うねえ。
> なお、私は動いてるスクリプトの中にpを何個かばらまいて挙動を追
> ったりするので、pの有無で(stdoutへの出力以外に)動作が変化して
> しまう可能性があるのはあんまり嬉しくないです。
私もそう思います。
Index: enumerator.c
===================================================================
--- enumerator.c (revision 20453)
+++ enumerator.c (working copy)
@@ -545,6 +545,68 @@ enumerator_rewind(VALUE obj)
return obj;
}
+static VALUE
+inspect_enumerator(VALUE obj, VALUE dummy, int recur)
+{
+ struct enumerator *e = enumerator_ptr(obj);
+ const char *cname = rb_obj_classname(obj);
+ VALUE eobj, str;
+ int tainted, untrusted;
+
+ if (recur) {
+ str = rb_sprintf("#<%s: ...>", cname);
+ OBJ_TAINT(str);
+ return str;
+ }
+
+ eobj = e->obj;
+
+ tainted = OBJ_TAINTED(eobj);
+ untrusted = OBJ_UNTRUSTED(eobj);
+
+ /* (1..100).each_cons(2) => "#<Enumerator: 1..100:each_cons(2)>" */
+ str = rb_sprintf("#<%s: ", cname);
+ rb_str_concat(str, rb_inspect(eobj));
+ rb_str_buf_cat2(str, ":");
+ rb_str_buf_cat2(str, rb_id2name(e->meth));
+
+ if (e->args) {
+ int argc = RARRAY_LEN(e->args);
+ VALUE *argv = RARRAY_PTR(e->args);
+
+ rb_str_buf_cat2(str, "(");
+
+ while (argc--) {
+ VALUE arg = *argv++;
+
+ rb_str_concat(str, rb_inspect(arg));
+ rb_str_buf_cat2(str, argc > 0 ? ", " : ")");
+
+ if (OBJ_TAINTED(arg)) tainted = Qtrue;
+ if (OBJ_UNTRUSTED(arg)) untrusted = Qtrue;
+ }
+ }
+
+ rb_str_buf_cat2(str, ">");
+
+ if (tainted) OBJ_TAINT(str);
+ if (untrusted) OBJ_UNTRUST(str);
+ return str;
+}
+
+/*
+ * call-seq:
+ * e.inspect => string
+ *
+ * Create a printable version of <i>e</i>.
+ */
+
+static VALUE
+enumerator_inspect(VALUE obj)
+{
+ return rb_exec_recursive(inspect_enumerator, obj, 0);
+}
+
/*
* Yielder
*/
@@ -779,6 +841,7 @@ Init_Enumerator(void)
rb_define_method(rb_cEnumerator, "with_object", enumerator_with_object, 1);
rb_define_method(rb_cEnumerator, "next", enumerator_next, 0);
rb_define_method(rb_cEnumerator, "rewind", enumerator_rewind, 0);
+ rb_define_method(rb_cEnumerator, "inspect", enumerator_inspect, 0);
rb_eStopIteration = rb_define_class("StopIteration", rb_eIndexError);
--
Akinori MUSHA / http://akinori.org/