ruby-changes:51319
From: matz <ko1@a...>
Date: Wed, 30 May 2018 17:24:58 +0900 (JST)
Subject: [ruby-changes:51319] matz:r63525 (trunk): object.c: Add a new alias `then` to `Kernel#yield_self`; [Feature #14594]
matz 2018-05-30 17:24:52 +0900 (Wed, 30 May 2018) New Revision: 63525 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=63525 Log: object.c: Add a new alias `then` to `Kernel#yield_self`; [Feature #14594] Modified files: trunk/object.c trunk/spec/ruby/core/kernel/yield_self_spec.rb Index: object.c =================================================================== --- object.c (revision 63524) +++ object.c (revision 63525) @@ -564,12 +564,13 @@ rb_obj_size(VALUE self, VALUE args, VALU https://github.com/ruby/ruby/blob/trunk/object.c#L564 /* * call-seq: + * obj.then {|x| block } -> an_object * obj.yield_self {|x| block } -> an_object * * Yields self to the block and returns the result of the block. * + * 3.next.then {|x| x**x }.to_s #=> "256" * "my string".yield_self {|s| s.upcase } #=> "MY STRING" - * 3.next.yield_self {|x| x**x }.to_s #=> "256" * */ @@ -4065,6 +4066,7 @@ InitVM_Object(void) https://github.com/ruby/ruby/blob/trunk/object.c#L4066 rb_define_method(rb_mKernel, "dup", rb_obj_dup, 0); rb_define_method(rb_mKernel, "itself", rb_obj_itself, 0); rb_define_method(rb_mKernel, "yield_self", rb_obj_yield_self, 0); + rb_define_method(rb_mKernel, "then", rb_obj_yield_self, 0); rb_define_method(rb_mKernel, "initialize_copy", rb_obj_init_copy, 1); rb_define_method(rb_mKernel, "initialize_dup", rb_obj_init_dup_clone, 1); rb_define_method(rb_mKernel, "initialize_clone", rb_obj_init_dup_clone, 1); Index: spec/ruby/core/kernel/yield_self_spec.rb =================================================================== --- spec/ruby/core/kernel/yield_self_spec.rb (revision 63524) +++ spec/ruby/core/kernel/yield_self_spec.rb (revision 63525) @@ -20,5 +20,10 @@ ruby_version_is "2.5" do https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/kernel/yield_self_spec.rb#L20 enum.peek.should equal object enum.first.should equal object end + + it "has an alias `then`" do + object = Object.new + object.then { 42 }.should equal 42 + end end end -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/