[#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:6326] RE: dup vs clone

From: Aleksi Niemel<aleksi.niemela@...>
Date: 2000-11-14 00:09:03 UTC
List: ruby-talk #6326
> 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?

Jim, 

I'd love to be able to give you definitive answer but I'm not. After some
quick source reading I have to say I'm more puzzled. Anyway the idea is
quite well stated at

  http://www.rubycentral.com/ref/ref_c_object.html#dup

and

  http://www.rubycentral.com/ref/ref_c_object.html#clone

So, the basic idea is that clone works like "memcpy", copying the whole
state in which the object was (including instance variables, taintedness and
other flags), while dup concentrates only to copy the "contents", or
payload, of the object.

Anyway, here's an example:

  # Couple of dup and clone differences

  a = []
  a.freeze
  b = a.clone
  c = a.dup
  p a.frozen?, b.frozen?, c.frozen?
    # => true, true, false

  class Ary < Array
    def foo
      @foo = "foo"
    end
    def inspect
      (@foo ? @foo : "") + " " + super
    end
  end

  a = Ary.new
  a.foo
  b = a.clone
  c = a.dup
  p a.inspect, b.inspect, c.inspect
    # => "foo []", "foo []", " []"

(I'm not sure Ary.dup (which is inherited from Array) should _not_ copy
instance variables. I'm not sure enough of the concepts, but it might be a
design flaw (or, in other words, a bug :)).

	- Aleksi

In This Thread

Prev Next