Robert Klemme
2/7/2009 4:36:00 PM
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