Hi, Robert,

In this case, I think the best way for you is to do it by yourself.
You can override an existing class in Ruby, even the one is a standard 
library class.

Provide a source file containing:

class Array
   def first=(v)
     self[0] = v
   end

   def last=(v)
     self[-1] = v
   end
end

and require it as you like.
And then you can use Array#first= and Array#last= as other standard 
methods for the class.

Yu-raku-an.


Robert Klemme wrote:
> On 27.12.2007 22:18, bbiker wrote:
>> On Dec 27, 4:59 am, Robert Klemme <shortcut... / googlemail.com> wrote:
>>> Hi,
>>>
>>> just today I came across a situation where I needed Array#last=
>>> because I wanted to do
>>>
>>> an_array.last += 1
>>>
>>> Does anybody else see this as useful?  Any issues with this?  If not
>>> I'll open an RCR.
>>>
>>> Kind regards
>>>
>>> robert
>>>
>>> -- 
>>> use.inject do |as, often| as.you_can - without end
>>
>> There's already array#last and array#first
>>
>> you csn do what you want with an_array[0] and an_array[-1]
> 
> Well, yes.  But I don't want to.  Instead I'd rather use last= and 
> first= in some circumstances much the same way as I sometimes rather use 
> last and first instead of [0] and [-1].
> 
> So far the only argument against I have seen so far is the question 
> about assignment to an empty array.  In that case I'd say, either raise 
> an exception or silently add the element.  Have to think about this a bit.
> 
> Cheers
> 
>     robert
> 
> 
> 

--------------------------------------
Easy + Joy + Powerful = Yahoo! Bookmarks x Toolbar
http://pr.mail.yahoo.co.jp/toolbar/