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

ruby-changes:23289

From: marcandre <ko1@a...>
Date: Mon, 16 Apr 2012 12:16:05 +0900 (JST)
Subject: [ruby-changes:23289] marcandRe: r35340 (trunk): * object.c: Add NilClass#to_h [Feature #6276]

marcandre	2012-04-16 12:15:56 +0900 (Mon, 16 Apr 2012)

  New Revision: 35340

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

  Log:
    * object.c: Add NilClass#to_h [Feature #6276]
      [ref #5008] [rubyspec:dc5ecddbd608]

  Modified files:
    trunk/NEWS
    trunk/object.c

Index: object.c
===================================================================
--- object.c	(revision 35339)
+++ object.c	(revision 35340)
@@ -1058,7 +1058,24 @@
 }
 
 /*
+ * Document-method: to_h
+ *
  *  call-seq:
+ *     nil.to_h    -> {}
+ *
+ *  Always returns an empty hash.
+ *
+ *     nil.to_h   #=> {}
+ */
+
+static VALUE
+nil_to_h(VALUE obj)
+{
+    return rb_hash_new();
+}
+
+/*
+ *  call-seq:
  *    nil.inspect  -> "nil"
  *
  *  Always returns the string "nil".
@@ -2896,6 +2913,7 @@
     rb_define_method(rb_cNilClass, "to_f", nil_to_f, 0);
     rb_define_method(rb_cNilClass, "to_s", nil_to_s, 0);
     rb_define_method(rb_cNilClass, "to_a", nil_to_a, 0);
+    rb_define_method(rb_cNilClass, "to_h", nil_to_h, 0);
     rb_define_method(rb_cNilClass, "inspect", nil_inspect, 0);
     rb_define_method(rb_cNilClass, "&", false_and, 1);
     rb_define_method(rb_cNilClass, "|", false_or, 1);
Index: NEWS
===================================================================
--- NEWS	(revision 35339)
+++ NEWS	(revision 35340)
@@ -43,6 +43,10 @@
       * added LoadError#path method to return the file name that could not be
         loaded.
 
+  * NilClass
+    * added method:
+      * added nil.to_h which returns {}
+
   * Signal
     * incompatible changes:
       * Signal.trap raises ArgumentError when :SEGV, :BUS, :ILL, :FPE, :VTALRM

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

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