And yet again more silly questions...

G

GGarramuno

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?
 
E

Eric Hodel

--UC+RhZhEc8lcmajv
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
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 - (e-mail address removed) - 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--
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,565
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top