Class: Cmdlet::Array::JoinPre

Inherits:
BaseCmdlet show all
Defined in:
lib/cmdlet/array/join_pre.rb

Overview

JoinPre: join an array of values with separator as a string and using the separator at the beginning of string

Instance Method Summary collapse

Methods inherited from BaseCmdlet

#tokenizer

Instance Method Details

#call(values, separator = ',') ⇒ String

Parameters:

  • values (String|Int)
    • array of values to join

  • separator (String) (defaults to: ',')
    • separator between values, defaults to comma

Returns:

  • (String)


12
13
14
15
16
17
18
19
# File 'lib/cmdlet/array/join_pre.rb', line 12

def call(values, separator = ',')
  return '' if values.nil? || !values.is_a?(::Array)

  values = values.reject(&:blank?)
  return '' if values.length.zero?

  "#{separator}#{values.join(separator)}"
end