And yet again more silly questions

  1. Is there any “which” or “where” command in ruby? That is, a
    command that will tell me which .rb, .so or so on defines the object,
    function or type (searching all appropiate paths --and files-- if
    needed)?

  2. Overloading/Inheritance question.

    Is there a way to call the .so functions from ruby directly?
    I’d like to overload the String=~ operator, but I’d like to
    eventually still call the native String=~ (which I assume is C code).
    That is:
    class String
    def =~(pat)
    # do something, like, say, count the regex calls
    C++::super(pat) # call original =~
    end
    end

If not possible, can I create my own string class inheriting from
String, but then alias it so all code calls my string class (even if I
create a sinple “blah” string constant and even code that is not my
own?)?

Also, what is the relationship between =~, index(), rindex(), match()
and the subs()? That is, is there a way to just overload a, say,
protected function and effect all regex at the same time? Or am I
bound to need to overload each individually?

  1. Overloading/Inheritance question.

    Is there a way to call the .so functions from ruby directly?
    I’d like to overload the String=~ operator, but I’d like to
    eventually still call the native String=~ (which I assume is C code).
    That is:
    class String
    def =~(pat)
    # do something, like, say, count the regex calls
    C++::super(pat) # call original =~
    end
    end

You can alias =~ to old_=~ (or similar) then call old_=~ from your
custom =~ method.

If not possible, can I create my own string class inheriting from
String, but then alias it so all code calls my string class (even if I
create a sinple “blah” string constant and even code that is not my
own?)?

If you create a String subclass, you can call super, and it will use
String’s =~ method.

···

GGarramuno (GGarramuno@aol.com) wrote:


Eric Hodel - drbrain@segment7.net - http://segment7.net
All messages signed with fingerprint:
FEC2 57F1 D465 EB15 5D6E 7C11 332A 551C 796C 9F04