[#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:01923] Re: object creation

From: Andrew Hunt <andy@...>
Date: 2000-03-16 19:33:37 UTC
List: ruby-talk #1923
    >Yukihiro Matsumoto writes:
    >> |preferred way to create a new MD5 object from C code?
    >> 
    >> I haven't settled my mind yet about this.
    >> 
    >> If you want to preserve `initialize' behavior, here's the way:

    >\cle writes:
    >
    >Perhaps I have misunderstood Andy, but I thought he suppose to have a
    >class MD5 that already exists as e.g. extension. But it has no
    >e.g. rb_md5_new function serving as C constructor like all built-in
    >classes of Ruby have!

Well, I actually asked both questions.

What I am trying to understand is the most legitimate way
to create objects from C.  In the case of built-in classes,
a "C-constructor" is available (rb_str_new, etc).  For extension
classes, the question is a little murkier.  I think the best
answer is that your own class should use Wrap_Struct/Make_Struct
and rb_bj_call_init, and that it should provide a C-level
constructor for others to use.  If that's not available, then
the next best thing would be to use funcall to call the "new"
method of the class.  I don't see any case where it
it would be prudent to call NEWOBJ/SETUPOBJ or poke around in
the internals of another class in order to instantiate it.

Does this sound okay? Or am I missing something?


/\ndy

--
Andrew Hunt, The Pragmatic Programmers, LLC.
Innovative Object-Oriented Software Development
web:   http://www.pragmaticprogrammer.com   email: andy@pragmaticprogrammer.com
--
Our New Book: "The Pragmatic Programmer" Published by Addison-Wesley Oct 1999
              (see www.pragmaticprogrammer.com/ppbook)
--

In This Thread

Prev Next