Proc#dup?

J

Jamis Buck

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
 
Y

Yukihiro Matsumoto

Hi,

In message "Re: Proc#dup?"

|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.

matz.
 
J

Jamis Buck

Yukihiro said:
Hi,

In message "Re: Proc#dup?"

|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
 
Y

Yukihiro Matsumoto

Hi,

In message "Re: Proc#dup?"

|> 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).

Hmm, singletons. That's good reason to leave clone. Let me consider.

matz.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,280
Latest member
BGBBrock56

Latest Threads

Top