> Wesley J Landaker wrote:
> ...
> Array.insert certainly isn't documented in the reference at
> rubycentral.com, however. If this is a new feature, you can always just
> add it to the old versions yourself. It's certainly not a subclass or
> anything, but the following might be good enough if you want just to be
> hidden from the unwieldy syntax:
> 
> class Array
>   def insert(pos, data)
>      self[pos,0] = data;
>   end
> end
> 
> You can now do Array.insert(pos, data) to insert 'data' at 'pos'. =)


This is premature, but since you posted something, so will I. <g>  I'm just
gathering together what you guys have posted.  I suppose it doesn't need to be
a subclass, but I guess I'm harping on the idea that if you want a linked list,
the class you use should be called that....


class LinkedList < Array
  def insert_at( pos, data )
    self[pos, 0] = data
    # (or self[pos..pos-1] but it's not really nice looking)
  end

  def insert_after( pos, data )
    self[pos + 1, 0] = data
  end

  def head
    return self[0]
  end

  def tail
    return self[1..self.length]
    # or:
    # self[1..-1]
  end

  def last
    return self[-1]
  end
end



Al


=====
Albert Davidson Chou

    Get answers to Mac questions at http://www.mac-mgrs.org/ .

__________________________________________________
Do You Yahoo!?
Get personalized email addresses from Yahoo! Mail - only $35 
a year!  http://personal.mail.yahoo.com/