Sha256: 0a3750bfe2436acb115245a9dc8bfda013afe5770b2da5cad175fe913811c838

Contents?: true

Size: 818 Bytes

Versions: 1

Compression:

Stored size: 818 Bytes

Contents

require 'nano/array/last'

class Array

  # Change the first element.
  #
  #   a = ["a","y","z"]
  #   a.first = "x"
  #   p a           #=> ["x","y","z"]
  #
  def first=(x)
    self[0] = x
  end

  # Alias for shift, which removes and returns
  # the first element in an array.
  #
  #   a = ["a","y","z"]
  #   a.first!      #=> "a"
  #   p a           #=> ["y","z"]
  #
  alias_method( :first!, :shift)

end


#  _____         _
# |_   _|__  ___| |_
#   | |/ _ \/ __| __|
#   | |  __/\__ \ |_
#   |_|\___||___/\__|
#
=begin test

  require 'test/unit'

  class TCArray < Test::Unit::TestCase

    def test_first_eq
      a = [1,2]
      a.first = 0
      assert_equal( [0,2], a )
    end

    def test_first!
      a = [1,2,3]
      assert_equal( 1, a.first! )
      assert_equal( [2,3], a )
    end

  end

=end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
facets-0.9.0 lib/nano/array/first.rb