Is there good reason to have two different methods for this?
array.at(index)
array.values_at(selector,... )
And then
array.delete_at(index)
Can't this take selector instead?
I imagine there are other methods related as well.
T.
Is there good reason to have two different methods for this?
array.at(index)
array.values_at(selector,... )
And then
array.delete_at(index)
Can't this take selector instead?
I imagine there are other methods related as well.
T.
Is there good reason to have two different methods for this?
array.at(index)
array.values_at(selector,... )
To help answer my own question. A problem arises with output on single element
results:
a = [1,2,3,4,5]
a.at(0) #=> 1
a.values_at(0) #=> [1]
The only alternatives I see for unification would be to have #at take an Array
or ignore nil:
a.at([0]) #=> [1]
a.at(0,nil) #=> [1]
But barring that (or a better solution), my REAL PROBLEM boils down to how
best to implement a method related to this but that doesn't have the same
difficulty. For example (completely contrived):
class Array
def part(n=nil)
if n
values_at(0..n)
else
at(0)
end
end
end
Is it better to have two methods instead --an #at_part and a #values_at_part?
Personally I prefer the single method but that seems to go against the
at/values_at grain. So that's why I'm inquiring into it.
And then
array.delete_at(index)
Can't this take selector instead?
This still seems reasonable.
T.
On Tuesday 14 December 2004 10:17 am, trans. (T. Onoma) wrote:
Hi,
Is there good reason to have two different methods for this?
array.at(index)
array.values_at(selector,... )
Return value, the latter returns an array of specified values.
And then
array.delete_at(index)
Can't this take selector instead?
The change would cause incompatibility in return values.
matz.
In message "Re: Array#at(selector,...)" on Wed, 15 Dec 2004 00:17:25 +0900, "trans. (T. Onoma)" <transami@runbox.com> writes:
Hi,
On Tuesday 14 December 2004 07:05 pm, Yukihiro Matsumoto wrote:
In message "Re: Array#at(selector,...)" > > on Wed, 15 Dec 2004 00:17:25 +0900, "trans. (T. Onoma)" <transami@runbox.com> writes:
>Is there good reason to have two different methods for this?
>
> array.at(index)
> array.values_at(selector,... )Return value, the latter returns an array of specified values.
>And then
>
> array.delete_at(index)
>
>Can't this take selector instead?The change would cause incompatibility in return values.
Ah I see, same difficulty. Thank you.
So then, I am under the impression that the two method approach is best --a
#delete_values_at for instance.
T.
Hi,
In message "Re: Array#at(selector,...)" on Wed, 15 Dec 2004 10:02:48 +0900, "trans. (T. Onoma)" <transami@runbox.com> writes:
So then, I am under the impression that the two method approach is best --a
#delete_values_at for instance.
If you want both functionality.
matz.