Top Level Namespace

Defined Under Namespace

Classes: CustomBoolean

Instance Method Summary collapse

Instance Method Details

#if_(condition) { ... } ⇒ CustomBoolean Also known as: if!, _if, if?

Equivalent of if for CustomBoolean truthiness. Differs from regular if as it uses CustomBoolean truthiness

Examples:

basic usage

# Use as follows:
if_(condition) { ... }

# Other conditionals chain on to the end of if_() as follows:
if_(condition) { ... }
.else { ... }

if-expression form

# Can turn if_() statement into if-expression by prefixing with a `+`
value = +if_(true) { :hello }
value #=> :hello

Parameters:

  • condition

    an expression to evaluate

Yields:

  • the block will be executed if the condition evalues to true

Returns:



78
79
80
81
82
# File 'lib/custom_boolean.rb', line 78

def if_(condition, &block)
  truth = !!CustomBoolean.truthy?(condition)
  bvalue = block.call if truth
  CustomBoolean.new(truth, bvalue)
end

#negate(expr) ⇒ Boolean

Equivalent of ! for CustomBoolean truthiness. Differs from regular ! as it uses CustomBoolean truthiness

Examples:

negate(obj)

Parameters:

  • expr

    The expression to be negated

Returns:

  • (Boolean)


57
58
59
# File 'lib/custom_boolean.rb', line 57

def negate(expr)
  !CustomBoolean.truthy?(expr)
end