/* * call-seq: * str.slice!(fixnum) => fixnum or nil * str.slice!(fixnum, fixnum) => new_str or nil * str.slice!(range) => new_str or nil * str.slice!(regexp) => new_str or nil * str.slice!(other_str) => new_str or nil * * Deletes the specified portion from <i>str</i>, and returns the portion * deleted. The forms that take a <code>Fixnum</code> will raise an * <code>IndexError</code> if the value is out of range; the <code>Range</code> * form will raise a <code>RangeError</code>, and the <code>Regexp</code> and * <code>String</code> forms will silently ignore the assignment. * * string = "this is a string" * string.slice!(2) #=> 105 * string.slice!(3..6) #=> " is " * string.slice!(/s.*t/) #=> "sa st" * string.slice!("r") #=> "r" * string #=> "thing" */ static VALUE rb_str_slice_bang(argc, argv, str) int argc; VALUE *argv; VALUE str; { VALUE result; VALUE buf[3]; int i; if (argc < 1 || 2 < argc) { rb_raise(rb_eArgError, "wrong number of arguments (%d for 1)", argc); } for (i=0; i<argc; i++) { buf[i] = argv[i]; } buf[i] = rb_str_new(0,0); result = rb_str_aref_m(argc, buf, str); if (!NIL_P(result)) { rb_str_aset_m(argc+1, buf, str); } return result; }