> 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
clone on the other hand tries to copy internal state as well.
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
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 ;-)