Method: Array#splice

Defined in:
lib/core/facets/array/splice.rb

#splice(*args) ⇒ Object

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



23
24
25
26
27
28
29
# File 'lib/core/facets/array/splice.rb', line 23

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