Method: Jig#plugn

Defined in:
lib/jig.rb

#plugn(*args, &block) ⇒ Object

call-seq:

plugn(n, item)       -> a_jig
plugn(range, array)  -> a_jig
plugn(symbol, array) -> a_jig
plugn(array)         -> a_jig
plugn(hash)          -> a_jig
plugn(item)          -> a_jig

Similar to #plug but gaps are identified by an integer offset, not by name. Unlike #index, and #slice, #plugn assumes that gaps are indexed consecutively starting with 0.

  • When the first argument is an integer, n, the n-th gap is replaced with the item.

  • When the first argument is a range, the gaps indexed by range are replaced with the items in array.

  • When the only argument is an array, the gaps indexed by 0...array.size are replaced with the items in the array.

  • When the only argument is a hash, the keys of the hash are taken as indices and the respective gaps are replaced with the associated values from the hash.

  • Any other single argument is taken as the replacement for the first gap.

Examples:

list = Jig[:item, ',', :item, ',', :item]
list.plugn(1, 'second')                           # => ",second,"
list.plugn(1..2, %w{second third})                # => ",second,third"
list.plugn('first')                               # => "first,,"
list.plugn(%w{first second})                      # => "first,second,"
list.plugn(0 => 'first', 2 => 'third')            # => "first,,third"


604
605
606
# File 'lib/jig.rb', line 604

def plugn(*args, &block)
  dup.plugn!(*args, &block)
end