Class: Array

Inherits:
Object
  • Object
show all
Defined in:
lib/jaspion/kilza.rb

Overview

Ruby class

Instance Method Summary collapse

Instance Method Details

#separate(sep = '') ⇒ Array

Inserts an separator between each element

Parameters:

  • sep (String) (defaults to: '')

    string to be used as separator

Returns:

  • (Array)

    the new array



36
37
38
39
40
41
# File 'lib/jaspion/kilza.rb', line 36

def separate(sep = '')
  a = self
  l = a.length - 2
  (0..l).each { |i| a.insert(((2 * i) + 1), sep) }
  a
end

#separate!(sep = '') ⇒ Object

Inserts an separator between each element

Parameters:

  • sep (String) (defaults to: '')

    string to be used as separator



46
47
48
49
# File 'lib/jaspion/kilza.rb', line 46

def separate!(sep = '')
  l = length - 2
  (0..l).each { |i| insert(((2 * i) + 1), sep) }
end