And yet again more silly questions...

Discussion in 'Ruby' started by GGarramuno, Dec 30, 2003.

  1. GGarramuno

    GGarramuno Guest

    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?
     
    GGarramuno, Dec 30, 2003
    #1
    1. Advertising

  2. GGarramuno

    Eric Hodel Guest

    --UC+RhZhEc8lcmajv
    Content-Type: text/plain; charset=us-ascii
    Content-Disposition: inline
    Content-Transfer-Encoding: quoted-printable

    GGarramuno () wrote:

    > 2) Overloading/Inheritance question.
    >=20
    > Is there a way to call the .so functions from ruby directly?
    > I'd like to overload the String=3D~ operator, but I'd like to
    > eventually still call the native String=3D~ (which I assume is C code).=

    =20
    > That is:
    > class String
    > def =3D~(pat)
    > # do something, like, say, count the regex calls
    > C++::super(pat) # call original =3D~
    > end
    > end


    You can alias =3D~ to old_=3D~ (or similar) then call old_=3D~ from your
    custom =3D~ 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 =3D~ method.

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


    --UC+RhZhEc8lcmajv
    Content-Type: application/pgp-signature
    Content-Disposition: inline

    -----BEGIN PGP SIGNATURE-----
    Version: GnuPG v1.2.2 (FreeBSD)

    iD8DBQE/8bVBMypVHHlsnwQRAoJuAJ4k9K1uSG5SLKbHh0hawleV3iIDBACgxZa8
    nn9d5WjTJGRv3QjuWjq0EbQ=
    =x3xK
    -----END PGP SIGNATURE-----

    --UC+RhZhEc8lcmajv--
     
    Eric Hodel, Dec 30, 2003
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Steven T. Hatton

    Header Files and Interfaces Yet Again

    Steven T. Hatton, Jun 9, 2004, in forum: C++
    Replies:
    11
    Views:
    512
    Kai-Uwe Bux
    Jun 16, 2004
  2. bill ramsay

    two silly questions

    bill ramsay, Jun 3, 2004, in forum: Python
    Replies:
    3
    Views:
    327
    bill ramsay
    Jun 4, 2004
  3. drs
    Replies:
    3
    Views:
    416
    Steven Bethard
    Dec 20, 2004
  4. Berehem
    Replies:
    4
    Views:
    598
    Lawrence Kirby
    Apr 28, 2005
  5. Gus Gassmann
    Replies:
    3
    Views:
    459
    Martin Honnen
    Sep 20, 2007
Loading...

Share This Page