Skip to content
Permalink
Browse files

object.c: Add a new alias `then` to `Kernel#yield_self`; [Feature #14…

…594]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63525 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
  • Loading branch information...
matz
matz committed May 30, 2018
1 parent 47f9dd8 commit d53ee008911b5c3b22cff1566a9ef7e7d4cbe183
Showing with 8 additions and 1 deletion.
  1. +3 −1 object.c
  2. +5 −0 spec/ruby/core/kernel/yield_self_spec.rb
@@ -564,12 +564,13 @@ rb_obj_size(VALUE self, VALUE args, VALUE obj)

/*
* 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)
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);
@@ -20,5 +20,10 @@
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

1 comment on commit d53ee00

@eregon

This comment has been minimized.

Copy link
Member

eregon commented on d53ee00 Jun 13, 2018

The hard naming decision was made, and a spec was written, thank you @matz!

Please sign in to comment.
You can’t perform that action at this time.