Sha256: 03951612433c07a56ca3fe29027a65d62a3147becd2fa89fe70932eff83a8e68

Contents?: true

Size: 853 Bytes

Versions: 16

Compression:

Stored size: 853 Bytes

Contents

require 'facet/array/store'

class Array

  # Modifies #[]= to accept an array of indexes for assignment.
  #
  #   a = ['a','b','c','d']
  #
  #   a[[1,-1]] = ['m','n']    #=> ['m','n']
  #   a                        #=> ['a','m','c','n']
  #
  def []=(*args)
    if Array === args.at(0)
      idx,vals = args.at(0),args.at(1)
      idx.each_with_index{ |a,i| store(a,vals.at(i)) }
      return values_at( *idx )
    else
      return store(*args)
    end
  end

end


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

  require 'test/unit'

  class TCArray < Test::Unit::TestCase

    def test_op_stroe
      a = ['a','o','z']
      a[[0,2]] = ['A','Z']
      assert_equal( ['A','o','Z'], a )
      a[[0,-1]] = ['W','Y']
      assert_equal( ['W','o','Y'], a )
    end

  end

=end

Version data entries

16 entries across 16 versions & 1 rubygems

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