diff --git a/object.c b/object.c index 6f4b123..274e0f3 100644 --- a/object.c +++ b/object.c @@ -736,6 +736,21 @@ rb_obj_tap(VALUE obj) return obj; } +/* + * call-seq: + * obj.pass{|x|...} -> block result + * + * Yields self to the block, and then returns result. + * + * Time.now.pass { |t| t.sunday? ? 'Yay!' : ':(' } + * + */ + +VALUE +rb_obj_pass(VALUE obj) +{ + return rb_yield(obj); +} /* * Document-method: inherited @@ -3510,6 +3525,7 @@ InitVM_Object(void) rb_define_method(rb_mKernel, "kind_of?", rb_obj_is_kind_of, 1); rb_define_method(rb_mKernel, "is_a?", rb_obj_is_kind_of, 1); rb_define_method(rb_mKernel, "tap", rb_obj_tap, 0); + rb_define_method(rb_mKernel, "pass", rb_obj_pass, 0); rb_define_global_function("sprintf", rb_f_sprintf, -1); /* in sprintf.c */ rb_define_global_function("format", rb_f_sprintf, -1); /* in sprintf.c */