[#6363] Re: rescue clause affecting IO loop behavior — ts <decoux@...>

>>>>> "D" == David Alan Black <dblack@candle.superlink.net> writes:

17 messages 2000/11/14
[#6367] Re: rescue clause affecting IO loop behavior — David Alan Black <dblack@...> 2000/11/14

Hello again --

[#6582] best way to interleaf arrays? — David Alan Black <dblack@...>

Hello --

15 messages 2000/11/26

[#6646] RE: Array Intersect (&) question — Aleksi Niemel<aleksi.niemela@...>

Ross asked something about widely known and largely ignored language (on

23 messages 2000/11/29
[#6652] RE: Array Intersect (&) question — rpmohn@... (Ross Mohn) 2000/11/29

aleksi.niemela@cinnober.com (Aleksi Niemel) wrote in

[#6723] Re: Array Intersect (&) question — Mathieu Bouchard <matju@...> 2000/12/01

> >Use a hash. Here's code to do both and more. It assumes that

[#6656] printing/accessing arrays and hashes — raja@... (Raja S.)

I'm coming to Ruby with a Python & Common Lisp background.

24 messages 2000/11/30

[ruby-talk:6330] Re: dup vs clone

From: Dave Thomas <Dave@...>
Date: 2000-11-14 00:28:16 UTC
List: ruby-talk #6330
jweirich@one.net writes:

> The "Programming Ruby" book indicates that there may be semantic
> differences between "dup" and "clone", particularly in descendent
> classes.  I'm not entirely sure why there would be a difference and
> exactly what that difference is.  Could someone elaborate?

dup is used to copy the contents of an object, but not necessarily all 
its internal attributes. You can think of dup as a kind of copy
contructor.

clone on the other hand tries to copy internal state as well.

For example:

     a = "hello"	# => "hello"
     a.freeze		# => "hello"

     b = a.dup		# => "hello"
     b.frozen?		# => false

     c = a.clone	# => "hello"
     c.frozen?		# => true



> 1) What's the best way to convert from a class name string to a class
>    object.  I've been using Eval(class_name) and trapping any NameErrors.
>    I could also search ObjectSpace looking for a match.  Is there a
>    better way?

Eval seems reasonable. If you _know_ that the name is a class, you
could also use Object.const_get(string)

   Object.const_get("Array")		# => Array

> 3) I would like to be able to tie classes and methods to source
>    files.  Currently, I don't see a direct way of doing this.  The
>    "Programming Ruby" book hints at using runtime callbacks to capture 
>    information about the system being defined.  I'm thinking about
>    wrapping "load" and "require" to record the file currently being
>    loaded and then hook into class and method definitions to record
>    that information.  Does this sound reasonable?

You'll need to remember to remove the file names from $" if you're
using require. You can also get the file name from set_trace_func it
you can find a safe method to call.

> 4) What about reloading source files?  I would like to be able to
>    reload a source file to get the latest changes.  I suspect that the 
>    naive approach might have problems.  Can source files be arbitrarily 
>    reloaded?

My guess is it would depend on the class. If a class sets global
state, then it might be tricky.


> How can I detect deleted methods?

You could hook Module.remove_method and .undef_method.


I'd personally like to see more browser support in 1.7, which is why I 
started the browser thread earlier. Your experiments are leading the
way to defining stuff that we might like (particularly if you start
working on compile and go and incremental compilation ;-)


Regards


Dave

In This Thread