Class: Cmdlet::Comparison::Default

Inherits:
BaseCmdlet show all
Defined in:
lib/cmdlet/comparison/default.rb

Overview

Default: Return true if **all of** the given values are truthy.

Instance Method Summary collapse

Methods inherited from BaseCmdlet

#tokenizer

Instance Method Details

#call(*values) ⇒ String

Return true when every value is truthy

Parameters:

  • values (Object)
    • one or more paramaters that may or may not contain nil

Returns:

  • (String)

    return true when every value is truthy



11
12
13
14
15
16
17
# File 'lib/cmdlet/comparison/default.rb', line 11

def call(*values)
  default_value = values[-1]

  find_value = values[0..-2].find { |value| !value.nil? }

  find_value || default_value
end