Sha256: cb1a7c29ce0859839243ef37648bf88271e8c94d9a65eef911d164e01de703e9

Contents?: true

Size: 534 Bytes

Versions: 2

Compression:

Stored size: 534 Bytes

Contents

require 'facets/array/store'

class Array

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

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

end

Version data entries

2 entries across 2 versions & 2 rubygems

Version Path
facets-glimmer-3.2.0 lib/core/facets/array/splice.rb
facets-3.1.0 lib/core/facets/array/splice.rb