Sha256: 3dcbede7fdf91582296b18eede1ecf26489e695d02deb5ff941ddccca3dac4db

Contents?: true

Size: 555 Bytes

Versions: 5

Compression:

Stored size: 555 Bytes

Contents

class Array

  # Splice acts a combination of #slice! and #store.
  # If two arguments are given it calls #store.
  # If a single argument is give 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

  # Store a value at a givne index.
  # Store is an alias for #[]=.
  alias_method :store, :[]=

end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
facets-2.7.0 lib/core/facets/array/splice.rb
facets-2.6.0 lib/core/facets/array/splice.rb
facets-2.5.0 lib/core/facets/array/splice.rb
facets-2.5.1 lib/core/facets/array/splice.rb
facets-2.5.2 lib/core/facets/array/splice.rb