I noticed, today, that Proc#dup fails ("allocator undefined for Proc"), but Proc#clone works.
Is this expected behavior?
$ ruby -ve "p proc { |a| puts 1 }.dup"
ruby 1.8.2 (2004-07-29) [i686-linux]
-e:1:in `dup': allocator undefined for Proc (NoMethodError)
from -e:1
$ ruby -ve "p proc { |a| puts 1 }.clone"
ruby 1.8.2 (2004-07-29) [i686-linux]
#<Proc:0x402ba958@-e:1>
I'm just used to using #dup. Should I be using #clone instead? I guess I've never taken the time to understand the semantic difference between the two.
- Jamis
···
--
Jamis Buck
jgb3@email.byu.edu
http://www.jamisbuck.org/jamis
Yukihiro Matsumoto wrote:
Hi,
>I noticed, today, that Proc#dup fails ("allocator undefined for Proc"), >but Proc#clone works.
>
>Is this expected behavior?
No. Both clone and dup should cause error (there should not be any
problem since Proc is immutable). Thank you.
Hmmm. That's not the answer I was hoping for, actually. 
Here's what I'm trying to do. I want to be able to add new methods to a proc's singleton class, but I don't want to modify the object that was passed to me. Then, I would like to be able to pass the new block to other methods that expect blocks (using the ampersand syntax).
I'm probably making things harder than they need to be. But it was a fun exercise. Guess I'll avoid doing #clone on Proc's, too, then.
- Jamis
···
In message "Re: Proc#dup?" > on Mon, 18 Oct 2004 07:56:34 +0900, Jamis Buck <jgb3@email.byu.edu> writes:
--
Jamis Buck
jgb3@email.byu.edu
http://www.jamisbuck.org/jamis