GGarramuno wrote: > ts <decoux / moulon.inra.fr> wrote in message news:<200401011438.i01Ecb824151 / moulon.inra.fr>... >> Yes, internally ruby is optimized to call directly the C function rather >> than calling the ruby method. > > Hmm... so, is there a way to overload/redefine it from ruby? no way of overloading or redefining from ruby that I know of, but you do have some other options. this optimization is used when the regexp is a a literal, which means you can get by this by not using a regexp literal, for example: pattern = /a/ # or pattern = Regexp.new('a') "abc" =~ pattern you could also prepend . to the =~ operator, which still looks operator-like but is interpreted as a method call: "abc" .=~ /a/ it would be best if ruby were to first check to see if =~ has been redefined before applying this optimization. > Also, how do you find out about the existence of this optimization? > By browsing the ruby C code? Or are there some docs available > somewhere? yep, the ruby source code is the primary source of documentation for this kind of stuff. Dave