Sha256: f708266caee4c431d70777d72d1d8d8d4658bbd82ae1da4f8914ae38420409c4

Contents?: true

Size: 838 Bytes

Versions: 1

Compression:

Stored size: 838 Bytes

Contents

class Array
  # Change the first element.
  #
  #   require 'facet/array/first&last='
  #
  #   a = ["a","y","z"]
  #   a.first = "x"
  #   p a           #=> ["x","y","z"]
  #
  def first=(x)
    self[0] = x
  end
  
  # Alias for unshift, which _pushes_
  # an element onto the front of an array.
  #
  #   require 'facet/array/first&last='
  #
  #   a = ["a","y","z"]
  #   a.first! "x"
  #   p a           #=> ["x","a","y","z"]
  #
  alias_method( :first!, :unshift)
  
  # Change the last element.
  #
  #   require 'facet/array/first&last='
  #
  #   a = [1,2,5]
  #   a.last = 3
  #   p a           #=> [1,2,3]
  #
  def last=(x)
    self[-1] = x
  end
  
  # Alias for push.
  #
  #   require 'facet/array/first&last='
  #
  #   a = [1,2]
  #   a.last! 3
  #   p a           #=> [1,2,3]
  #  
  alias_method( :last!, :push)
  
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
facets-0.6.3 lib/facet/array/first&last.rb