[#38392] Enumerable#gather_each — Tanaka Akira <akr@...>

ときに、複数行をまとめて扱いたいことがあります。

47 messages 2009/05/09
[#38394] Re: Enumerable#gather_each — ujihisa <ujihisa@...> 2009/05/09

ujihisaと申します。

[#38400] Re: Enumerable#gather_each — Yukihiro Matsumoto <matz@...> 2009/05/09

まつもと ゆきひろです

[#38399] Re: Enumerable#gather_each — "Akinori MUSHA" <knu@...> 2009/05/09

At Sat, 9 May 2009 15:30:20 +0900,

[#38405] Re: Enumerable#gather_each — Tanaka Akira <akr@...> 2009/05/10

In article <86r5yy2nrg.knu@iDaemons.org>,

[#38417] Re: Enumerable#gather_each — "Akinori MUSHA" <knu@...> 2009/05/10

At Sun, 10 May 2009 10:08:47 +0900,

[#38524] [Bug #1503] -Kuをつけた時、/[#{s}]/n と Regexp.new("[#{s}]",nil,"n") で実行結果が異なる — sinnichi eguchi <redmine@...>

Bug #1503: -Kuをつけた時、/[#{s}]/n と Regexp.new("[#{s}]",nil,"n") で実行結果が異なる

8 messages 2009/05/22

[ruby-dev:38491] Re: [Bug:1.9] exact Time and inexact Time

From: Yusuke ENDOH <mame@...>
Date: 2009-05-18 16:02:35 UTC
List: ruby-dev #38491
遠藤です。

2009/05/18 9:05 Yukihiro Matsumoto <matz@ruby-lang.org>:
> まつもと ゆきひろです
>
> In message "Re: [ruby-dev:38484] Re: [Bug:1.9] exact Time and inexact Time"
>    on Sun, 17 May 2009 21:46:01 +0900, Tanaka Akira <akr@fsij.org> writes:
>
> |Time#to_r を加えるのはあり得ると思います。
>
> 私もこちらに賛成します。


それではパッチを書きました。

  - Time#to_r を追加
  - Time#- は常に Float を返す (1.9.1 と同じ挙動)

特に反対がなければコミットしようと思います。


Index: time.c
===================================================================
--- time.c	(revision 23485)
+++ time.c	(working copy)
@@ -2277,6 +2277,30 @@

 /*
  *  call-seq:
+ *     time.to_r => Rational
+ *
+ *  Returns the value of <i>time</i> as a rational number of seconds
+ *  since the Epoch.
+ *
+ *     t = Time.now
+ *     p t.to_r            #=> (8807170717088293/8388608)
+ *
+ *  This method is intended to be used to get an accurate value
+ *  representing nanoseconds from the Epoch.  You can use this
+ *  to convert time to another Epoch.
+ */
+
+static VALUE
+time_to_r(VALUE time)
+{
+    struct time_object *tobj;
+
+    GetTimeval(time, tobj);
+    return tobj->timev;
+}
+
+/*
+ *  call-seq:
  *     time.usec    => int
  *     time.tv_usec => int
  *
@@ -2803,7 +2827,7 @@
 	struct time_object *tobj2;

 	GetTimeval(time2, tobj2);
-        return sub(tobj->timev, tobj2->timev);
+        return rb_Float(sub(tobj->timev, tobj2->timev));
     }
     return time_add(tobj, time2, -1);
 }
@@ -3682,6 +3706,7 @@

     rb_define_method(rb_cTime, "to_i", time_to_i, 0);
     rb_define_method(rb_cTime, "to_f", time_to_f, 0);
+    rb_define_method(rb_cTime, "to_r", time_to_r, 0);
     rb_define_method(rb_cTime, "<=>", time_cmp, 1);
     rb_define_method(rb_cTime, "eql?", time_eql, 1);
     rb_define_method(rb_cTime, "hash", time_hash, 0);

-- 
Yusuke ENDOH <mame@tsg.ne.jp>

In This Thread