Sha256: 8fe5627f276e7c451ccb0c58add2d5df54c67c61eddaffa6bd66b9605ce62ab5

Contents?: true

Size: 659 Bytes

Versions: 17

Compression:

Stored size: 659 Bytes

Contents

class Array

  # Modifies #[] to also accept an array of indexes.
  #
  #   a = ['a','b','c','d','e','f']
  #
  #   a[[1]]      #=> ['b']
  #   a[[1,1]]    #=> ['b','b']
  #   a[[1,-1]]   #=> ['b','f']
  #   a[[0,2,4]]  #=> ['a','c','e']
  #
  def [](*args)
    return values_at(*args.at(0)) if Array === args.at(0)
    return slice(*args)
  end

end


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

  require 'test/unit'

  class TCArray < Test::Unit::TestCase

    def test_op_fetch
      a = ['a','b','c','d','e','f']
      assert_equal( ['b','f'], a[[1,-1]] )
    end

  end

=end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
facets-1.0.3 packages/core/lib/facet/array/op_fetch.rb
facets-0.9.0 lib/nano/array/op_fetch.rb
facets-1.0.0 lib/facet/array/op_fetch.rb
facets-1.3.0 lib/facets/core/array/op_fetch.rb
facets-1.1.0 lib/facet/array/op_fetch.rb
facets-1.2.0 lib/facets/core/array/op_fetch.rb
facets-1.2.1 lib/facets/core/array/op_fetch.rb
facets-1.3.1 lib/facets/core/array/op_fetch.rb
facets-1.3.2 lib/facets/core/array/op_fetch.rb
facets-1.3.3 lib/facets/core/array/op_fetch.rb
facets-1.4.2 lib/facets/core/array/op_fetch.rb
facets-1.4.0 lib/facets/core/array/op_fetch.rb
facets-1.4.1 lib/facets/core/array/op_fetch.rb
facets-1.4.3 lib/facets/core/array/op_fetch.rb
facets-1.4.5 lib/facets/core/array/op_fetch.rb
facets-1.4.4 lib/facets/core/array/op_fetch.rb
facets-1.7.0 lib/facets/core/array/op_fetch.rb