mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* object.c: Add NilClass#to_h [Feature #6276]
[ref #5008] [rubyspec:dc5ecddbd608] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@35340 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
f92be2c01a
commit
33399fe824
2 changed files with 22 additions and 0 deletions
4
NEWS
4
NEWS
|
@ -43,6 +43,10 @@ with all sufficient information, see the ChangeLog file.
|
||||||
* added LoadError#path method to return the file name that could not be
|
* added LoadError#path method to return the file name that could not be
|
||||||
loaded.
|
loaded.
|
||||||
|
|
||||||
|
* NilClass
|
||||||
|
* added method:
|
||||||
|
* added nil.to_h which returns {}
|
||||||
|
|
||||||
* Signal
|
* Signal
|
||||||
* incompatible changes:
|
* incompatible changes:
|
||||||
* Signal.trap raises ArgumentError when :SEGV, :BUS, :ILL, :FPE, :VTALRM
|
* Signal.trap raises ArgumentError when :SEGV, :BUS, :ILL, :FPE, :VTALRM
|
||||||
|
|
18
object.c
18
object.c
|
@ -1057,6 +1057,23 @@ nil_to_a(VALUE obj)
|
||||||
return rb_ary_new2(0);
|
return rb_ary_new2(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 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:
|
* call-seq:
|
||||||
* nil.inspect -> "nil"
|
* 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_f", nil_to_f, 0);
|
||||||
rb_define_method(rb_cNilClass, "to_s", nil_to_s, 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_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, "inspect", nil_inspect, 0);
|
||||||
rb_define_method(rb_cNilClass, "&", false_and, 1);
|
rb_define_method(rb_cNilClass, "&", false_and, 1);
|
||||||
rb_define_method(rb_cNilClass, "|", false_or, 1);
|
rb_define_method(rb_cNilClass, "|", false_or, 1);
|
||||||
|
|
Loading…
Reference in a new issue