aboutsummaryrefslogtreecommitdiffstats
path: root/object.c
diff options
context:
space:
mode:
Diffstat (limited to 'object.c')
-rw-r--r--object.c18
1 files changed, 18 insertions, 0 deletions
diff --git a/object.c b/object.c
index 59bdea0c18..3c4445cb59 100644
--- a/object.c
+++ b/object.c
@@ -1058,6 +1058,23 @@ nil_to_a(VALUE obj)
}
/*
+ * 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"
*
@@ -2896,6 +2913,7 @@ Init_Object(void)
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);