[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

Re: Special Hash Constructors

Trans

2/7/2009 3:33:00 PM



On Feb 7, 8:18=A0am, Robert Klemme <shortcut...@googlemail.com> wrote:

> Where's the point of the rescue clause? =A0The error will show up much
> later, i.e. after the method has returned.

Why would the error show later? It is just so one could pass a
immutable, like 0 to #with without raising an error b/c it doesn't
respond to #dup.

> Also, as Tom pointed out, this is not the same as what I proposed - not
> even similar.

It's not?

Hash.with([])

is not the same as

Hash.with_arrays

?

2 Answers

Robert Klemme

2/7/2009 4:36:00 PM

0

On 07.02.2009 16:32, Trans wrote:
>
> On Feb 7, 8:18 am, Robert Klemme <shortcut...@googlemail.com> wrote:
>
>> Where's the point of the rescue clause? The error will show up much
>> later, i.e. after the method has returned.
>
> Why would the error show later? It is just so one could pass a
> immutable, like 0 to #with without raising an error b/c it doesn't
> respond to #dup.

The code block is not executed when you invoke Hash.with - hence there
can't be an error. When you need it the rescue block is not there as
the block is called from a different context.

>> Also, as Tom pointed out, this is not the same as what I proposed - not
>> even similar.
>
> It's not?
>
> Hash.with([])
>
> is not the same as
>
> Hash.with_arrays
>
> ?
>

It's closer than I initially thought. But: I wanted these two special
methods and not yet another generic method. For that, we have the
original Hash.new already. Your version still needs an argument. Since
I see that we are using an Array most of the time anyway that can be
coded into the method. No need for another generic approach IMHO.

Cheers

robert

Simon Krahnke

2/7/2009 6:06:00 PM

0

* Robert Klemme <shortcutter@googlemail.com> (17:35) schrieb:

> It's closer than I initially thought. But: I wanted these two special
> methods and not yet another generic method. For that, we have the
> original Hash.new already. Your version still needs an argument. Since
> I see that we are using an Array most of the time anyway that can be
> coded into the method. No need for another generic approach IMHO.

The difference between the existing and the new generic is the
assignment. I see the block form of new most often because some mutable
object should be assigned on read.

mfg, simon .... l