[前][次][番号順一覧][スレッド一覧]

ruby-changes:10354

From: knu <ko1@a...>
Date: Fri, 30 Jan 2009 15:45:44 +0900 (JST)
Subject: [ruby-changes:10354] Ruby:r21898 (ruby_1_8): * proc.c (Init_Proc): add '===' operator to use procs in when

knu	2009-01-30 15:45:32 +0900 (Fri, 30 Jan 2009)

  New Revision: 21898

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=21898

  Log:
    * proc.c (Init_Proc): add '===' operator to use procs in when
      clause of the case statement.  inspired by <http://www.aimred.com/news/developers/2008/08/14/unlocking_the_power_of_case_equality_proc/>.

  Modified files:
    branches/ruby_1_8/ChangeLog
    branches/ruby_1_8/NEWS
    branches/ruby_1_8/eval.c

Index: ruby_1_8/NEWS
===================================================================
--- ruby_1_8/NEWS	(revision 21897)
+++ ruby_1_8/NEWS	(revision 21898)
@@ -56,6 +56,10 @@
 
     Renamed from ENV.index.
 
+  * Proc#===
+
+    New method primarily for use in the case-when construct.
+
   * Range#cover?
 
     New alias to #include? for the forward compatibility with 1.9, in
Index: ruby_1_8/ChangeLog
===================================================================
--- ruby_1_8/ChangeLog	(revision 21897)
+++ ruby_1_8/ChangeLog	(revision 21898)
@@ -1,3 +1,8 @@
+Fri Jan 30 15:41:51 2009  Akinori MUSHA  <knu@i...>
+
+	* proc.c (Init_Proc): add '===' operator to use procs in when
+	  clause of the case statement.  inspired by <http://www.aimred.com/news/developers/2008/08/14/unlocking_the_power_of_case_equality_proc/>.
+
 Thu Jan 29 12:18:54 2009  Technorama Ltd.  <oss-ruby@t...>
 
 	* lib/securerandom.rb: new method SecureRandom#uuid
Index: ruby_1_8/eval.c
===================================================================
--- ruby_1_8/eval.c	(revision 21897)
+++ ruby_1_8/eval.c	(revision 21898)
@@ -8975,6 +8975,14 @@
  *     	from prog.rb:5
  */
 
+/*
+ *  call-seq:
+ *     prc === obj   => obj
+ *  
+ *  Invokes the block, with <i>obj</i> as the block's parameter.  It is
+ *  to allow a proc object to be a target of when clause in the case statement.
+ */
+
 VALUE
 rb_proc_call(proc, args)
     VALUE proc, args;		/* OK */
@@ -10105,6 +10113,7 @@
     rb_define_method(rb_cProc, "call", rb_proc_call, -2);
     rb_define_method(rb_cProc, "arity", proc_arity, 0);
     rb_define_method(rb_cProc, "[]", rb_proc_call, -2);
+    rb_define_method(rb_cProc, "===", rb_proc_call, -2);
     rb_define_method(rb_cProc, "==", proc_eq, 1);
     rb_define_method(rb_cProc, "to_s", proc_to_s, 0);
     rb_define_method(rb_cProc, "to_proc", proc_to_self, 0);

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]