Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > And yet again more silly questions...

Reply
Thread Tools

And yet again more silly questions...

 
 
GGarramuno
Guest
Posts: n/a
 
      12-30-2003
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?
 
Reply With Quote
 
 
 
 
Eric Hodel
Guest
Posts: n/a
 
      12-30-2003
--UC+RhZhEc8lcmajv
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

GGarramuno ((E-Mail Removed)) 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://www.velocityreviews.com/forums/(E-Mail 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/8bVBMypVHHlsnwQRAoJuAJ4k9K1uSG5SLKbHh0hawleV3iIDBA CgxZa8
nn9d5WjTJGRv3QjuWjq0EbQ=
=x3xK
-----END PGP SIGNATURE-----

--UC+RhZhEc8lcmajv--

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Battlefield 2 New Patch Released (yet Again...) Silverstrand Front Page News 4 07-20-2005 04:33 PM
Yet another book recommendation, but for someone who can program and yet does not the terminology well Berehem C Programming 4 04-28-2005 05:25 PM
silly question - is there a nikon D80 available anywhere yet? C. Falise Digital Photography 1 02-26-2005 11:44 PM
Header Files and Interfaces Yet Again Steven T. Hatton C++ 11 06-16-2004 06:28 AM
Microsoft fails yet again to deliver as promised Tobin MCSD 31 12-07-2003 06:19 AM



Advertisments