Because then x.last(5) = [1, 2, 3, 4, 5] would also have to work, but this
is currently syntactically impossible.
I once submitted a RCR to allow that syntax, but it wasn't clear whether
the community or matz really wanted to have this:
I'd like that. I would use this to acces class variables as
an collection. For example: myobj.names(2) = "myname"
It would work like myobj.names[2] = "myname", but call the method
on myobj in stead of myobj.names.
Regards,
Kristof
···
On Wed, 21 Jul 2004 13:37:15 +0200, Florian Gross wrote:
I'm not enthusiastic for them. I feel like that they are not as
useful as, "push" method for example.
matz.
For me it seems natural that if I can access the value from x.first I would also be able to update x.first.
It's not a great deal but first and last read better that [0] and [-1] and I would like to use them all the time without forever having to overload the array class.
I can live with it but having been away from Ruby for a bit this is the first thing I tripped up on (other than the use of ; to end lines!)
>Is there any chance that
>
>class Array
> def first=(v)
> self[0] = v
> end
>
> def last=(v)
> self[-1] = v
> end
>end
>
>might become part of the core? matz?
I'm not enthusiastic for them. I feel like that they are not as
useful as, "push" method for example.
Me too. Then, there should be also Range#last= and Range#first=, but I don't like them too much.
Regards,
Michael
···
In message "Re: Little query" > on 04/07/21, Peter Hickman <peter@semantico.com> writes:
"Michael Neumann" <mneumann@ntecs.de> schrieb im Newsbeitrag
news:40FE7141.6050809@ntecs.de...
Yukihiro Matsumoto wrote:
> Hi,
>
>
> >Is there any chance that
> >
> >class Array
> > def first=(v)
> > self[0] = v
> > end
> >
> > def last=(v)
> > self[-1] = v
> > end
> >end
> >
> >might become part of the core? matz?
>
> I'm not enthusiastic for them. I feel like that they are not as
> useful as, "push" method for example.
Me too. Then, there should be also Range#last= and Range#first=, but I
don't like them too much.
IMHO Range is a different cup of tea because Ranges are immutable. So
assigning would not be approrpiate here.
robert
···
> In message "Re: Little query" > > on 04/07/21, Peter Hickman <peter@semantico.com> writes: