Sha256: ce6fcff8e6a421065a1554db12a9951e9e960550c1572e7cd90c879feb634cca

Contents?: true

Size: 556 Bytes

Versions: 7

Compression:

Stored size: 556 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

7 entries across 7 versions & 2 rubygems

Version Path
facets-2.4.0 lib/facets/array/splice.rb
facets-2.4.1 lib/facets/array/splice.rb
facets-2.4.3 lib/core/facets/array/splice.rb
facets-2.4.2 lib/core/facets/array/splice.rb
facets-2.4.4 lib/core/facets/array/splice.rb
facets-2.4.5 lib/core/facets/array/splice.rb
mack-facets-0.8.2 lib/gems/facets-2.4.5/lib/core/facets/array/splice.rb