[#1816] Ruby 1.5.3 under Tru64 (Alpha)? — Clemens Hintze <clemens.hintze@...>

Hi all,

17 messages 2000/03/14

[#1989] English Ruby/Gtk Tutorial? — schneik@...

18 messages 2000/03/17

[#2241] setter() for local variables — ts <decoux@...>

18 messages 2000/03/29

[ruby-talk:01956] Re: object creation

From: Clemens Hintze <c.hintze@...>
Date: 2000-03-17 07:39:50 UTC
List: ruby-talk #1956
Dave Thomas writes:
> Clemens Hintze <c.hintze@gmx.net> writes:

...

> > It would be easier, of course. But it would also be slower and would
> > invoke the interpreter again. I would code an own local function, that
> > call the fgdbm_s_open function directly. Then I would use this local
> > function in my extension.
> 
> Now I'm probably missing something, but wouldn't calling the
> constructor indirectly also allow the users of the extension override
> the default initialization?
> 
> To me, it seems like the interpreter goes to a lot of trouble to use
> rb_funcall to ensure that it correctly allows the user to override
> methods. Shouldn't the extensions do likewise?

Boommer ... ... ... :-)

Now you have hit me while I am standing on the left foot ... :-)

I must admit, I have never thought of this. Overwriting class creation
methods? I do not like this too much! It is possible in Ruby, as Ruby
takes all the methods the same. But I never thought to do this!

Perhaps I am wrong here, but I do not believe the interpreter use
rb_funcall in internal classes to allow user to overwrite existing
methods. It should do it to allow, that subclasses provide another
implementation of a certain method.

I consider using rb_funcall or direct call within extensions more like
the late binding/early binding question in C++.

IMHO, it is very dangerous to overwrite class creation methods of
extension classes if the class was not written by me! Because the
constructor or the initializator (?right word?)  have to allocate
memory. Memory that is not necessarily directly visible on Ruby
level. If I overwrite such a method, I would have to call it,
'though. Otherwise the memory wouldn't be allocated or the instance
would not be initialized correctly.

Built-in classes do not use rb_funcall all the time! Please consider
how often you can see a

   RSTRING(obj)->len

or a

   RARRAY(obj)->len

therein. If I would overwrite String#length or Array#length the
built-in classes would not honor that, however!

I think there is perhaps no "true" way here! The extension developper
has to decide from case to case, if s/he wants to call the C function
directly or using rb_funcall.

Other opinions to that topic? :-)

> 
> Regards
> 
> 
> Dave

\cle

-- 
Clemens Hintze  mailto: c.hintze@gmx.net

In This Thread