[#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:37248] [Feature:1.9] Enumerator#inspect
遠藤です。
Enumerator の中身をわかりやすく表示してくれる Enumerator#inspect を
提供すると便利だと思います。例えばこんな感じ。
$ ruby19 -e 'g = (1..1000).each; p g'
#<Enumerator:[1, 2, 3, ...(snipped)]>
現状は #<Enumerator:0x8269654> とかなので、デバッグには不便です。
以下はたたき台のパッチです。
Index: enumerator.c
===================================================================
--- enumerator.c (revision 20448)
+++ enumerator.c (working copy)
@@ -545,7 +545,69 @@
return obj;
}
+static VALUE
+inspect_enumerator_i(VALUE val, VALUE *memo)
+{
+ VALUE str = memo[0];
+ if (memo[1] >= 3) {
+ rb_str_buf_cat2(str, ", ...(snipped)");
+ rb_iter_break();
+ }
+ if (memo[1] > 0) rb_str_buf_cat2(str, ", ");
+ rb_str_buf_append(str, rb_inspect(val));
+ memo[1]++;
+ if (OBJ_TAINTED(val)) memo[2] = Qtrue;
+ if (OBJ_UNTRUSTED(val)) memo[3] = Qtrue;
+ return Qnil;
+}
+
+static VALUE
+inspect_enumerator(VALUE obj, VALUE dummy, int recur)
+{
+ const char *cname = rb_obj_classname(obj);
+ struct enumerator *e;
+ int argc = 0;
+ VALUE *argv = 0;
+ VALUE str;
+ VALUE memo[4];
+
+ if (recur) {
+ str = rb_sprintf("#<%s:[...]>", cname);
+ OBJ_TAINT(str);
+ return str;
+ }
+
+ memo[0] = str = rb_sprintf("#<%s:[", cname);
+ memo[1] = (VALUE)0;
+ memo[2] = OBJ_TAINTED(obj);
+ memo[3] = OBJ_UNTRUSTED(obj);
+ e = enumerator_ptr(obj);
+ if (e->args) {
+ argc = RARRAY_LEN(e->args);
+ argv = RARRAY_PTR(e->args);
+ }
+ rb_block_call(e->obj, e->meth, argc, argv,
+ inspect_enumerator_i, (VALUE)memo);
+ rb_str_buf_cat2(str, "]>");
+ if (memo[2]) OBJ_TAINT(str);
+ if (memo[3]) OBJ_UNTRUST(str);
+ return str;
+}
+
/*
+ * call-seq:
+ * e.inspect => "#<Enumerator:[1, 2, 3, ...(snipped)]>"
+ *
+ * Create a printable version of <i>e</i>.
+ */
+
+static VALUE
+enumerator_inspect(VALUE obj)
+{
+ return rb_exec_recursive(inspect_enumerator, obj, 0);
+}
+
+/*
* Yielder
*/
static void
@@ -779,6 +841,7 @@
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);
Index: lib/pp.rb
===================================================================
--- lib/pp.rb (revision 20448)
+++ lib/pp.rb (working copy)
@@ -339,6 +339,27 @@
end
end
+class Enumerator
+ def pretty_print(q)
+ s = self.class.to_s
+ q.group(s.size + 3, '#<' + s + ':', ']>') {
+ idx = 0
+ q.seplist(take(4)) {|v|
+ if idx < 3
+ q.pp v
+ else
+ q.text "...(snipped)"
+ end
+ idx += 1
+ }
+ }
+ end
+
+ def pretty_print_cycle(q)
+ q.text('#<' + self.class.to_s + ':[...]')
+ end
+end
+
class Hash
def pretty_print(q)
q.pp_hash self
--
Yusuke ENDOH <mame@tsg.ne.jp>