Sha256: ef15ba51960e67499379de7d5a5b7a0b706ebe528d6b86ac847caeaf1335727e

Contents?: true

Size: 488 Bytes

Versions: 7

Compression:

Stored size: 488 Bytes

Contents

require 'facets/array/store'

class Array

  # Splice acts a combination of #slice! and #store.
  # If two arguments are given it calls #store.
  # If a single argument is given it calls slice!.
  #
  #   a = [1,2,3]
  #   a.splice(1)    #=> 2
  #   a              #=> [1,3]
  #
  #   a = [1,2,3]
  #   a.splice(1,4)  #=> 4
  #   a              #=>[1,4,3]
  #
  # CREDIT: Trans

  def splice(*args)
    if args.size == 1
      slice!(*args)
    else
      store(*args)
    end
  end

end

Version data entries

7 entries across 6 versions & 1 rubygems

Version Path
facets-2.9.3 lib/core/facets/array/splice.rb
facets-2.9.2 lib/core/facets/array/splice.rb
facets-2.9.2 src/core/facets/array/splice.rb
facets-2.9.1 lib/core/facets/array/splice.rb
facets-2.9.0 lib/core/facets/array/splice.rb
facets-2.9.0.pre.2 lib/core/facets/array/splice.rb
facets-2.9.0.pre.1 lib/core/facets/array/splice.rb