public Method

Kernel.gsub(...)

gsub(pattern, replacement)     string
gsub(pattern) {|...| block }   string

Equivalent to $_.gsub…, except that $_ receives the modified result.

$_ = "quick brown fox"
gsub /[aeiou]/, '*'   #=> "q**ck br*wn f*x"
$_                    #=> "q**ck br*wn f*x"

Source Code

/*
*  call-seq:
*     gsub(pattern, replacement)    => string
*     gsub(pattern) {|...| block }  => string
*  
*  Equivalent to <code>$_.gsub...</code>, except that <code>$_</code>
*  receives the modified result.
*     
*     $_ = "quick brown fox"
*     gsub /[aeiou]/, '*'   #=> "q**ck br*wn f*x"
*     $_                    #=> "q**ck br*wn f*x"
*/

static VALUE
rb_f_gsub(argc, argv)
   int argc;
   VALUE *argv;
{
   VALUE str = rb_str_dup(uscore_get());

   if (NIL_P(rb_str_gsub_bang(argc, argv, str)))
       return str;
   rb_lastline_set(str);
   return str;
}
Comments

Have your say
Please use Textile formatting (click here for a cheat sheet). Use <code/> and <pre/> for code samples.
Click here to login with OpenID to to post comments.