Project

General

Profile

Feature #7388 ยป object_embed.patch

zzak (zzak _), 11/19/2012 07:40 AM

View differences:

ChangeLog
Wed Dec 14 22:23:14 2011 <pyr@omega>
* object.c: Add Object#embed which works like tap but returns the block's
value. Useful in method chains.
Wed Dec 14 21:58:42 2011 NAKAMURA Usaku <usa@ruby-lang.org>
* test/ruby/test_io_m17n.rb
object.c
return obj;
}
/*
* call-seq:
* obj.embed{|x|...} -> obj
*
* Yields <code>x</code> to the block, and then returns the return value
* of the block. The primary purpose of this method is to modify the object
* in place in a method chain.
*
* (1..10).embed {|x| {:numbers => x}}
*
*/
VALUE
rb_obj_embed(VALUE obj)
{
VALUE retval;
retval = rb_yield(obj);
return retval;
}
/*
* Document-method: inherited
......
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, "embed", rb_obj_embed, 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 */
    (1-1/1)