[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Proc#dup?

Jamis Buck

10/17/2004 10:57:00 PM

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


3 Answers

Yukihiro Matsumoto

10/19/2004 2:26:00 PM

0

Hi,

In message "Re: Proc#dup?"
on Mon, 18 Oct 2004 07:56:34 +0900, Jamis Buck <jgb3@email.byu.edu> writes:

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


Jamis Buck

10/19/2004 2:38:00 PM

0

Yukihiro Matsumoto wrote:
> Hi,
>
> In message "Re: Proc#dup?"
> on Mon, 18 Oct 2004 07:56:34 +0900, Jamis Buck <jgb3@email.byu.edu> writes:
>
> |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

--
Jamis Buck
jgb3@email.byu.edu
http://www.jamisbuck...


Yukihiro Matsumoto

10/19/2004 4:31:00 PM

0

Hi,

In message "Re: Proc#dup?"
on Tue, 19 Oct 2004 23:38:21 +0900, Jamis Buck <jgb3@email.byu.edu> writes:

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