Parent

Array

Add the #separate and #separate! methods to Array.

Public Instance Methods

separate( value=:__no_arg__, &block ) click to toggle source

Returns a new Array that has had a new member inserted between all of the current ones. The value used is the given value argument unless a block is given, in which case the block is called once for each pair of the Array, and the return value is used as the separator.

# File lib/linguistics/en.rb, line 1706
def separate( value=:__no_arg__, &block )
    ary = self.dup
    ary.separate!( value, &block )
    return ary
end
separate!( value=:__no_arg__ ) click to toggle source

The same as #separate, but modifies the Array in place.

# File lib/linguistics/en.rb, line 1713
def separate!( value=:__no_arg__ )
    raise ArgumentError, "wrong number of arguments: (0 for 1)" if
        value == :__no_arg__ && !block_given?

    (1..( (self.length * 2) - 2 )).step(2) do |i|
        if block_given?
            self.insert( i, yield(self[i-1,2]) )
        else
            self.insert( i, value )
        end
    end
    self
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.