Class: FalseClass

Inherits:
Object show all
Defined in:
lib/errgonomic/core_ext/bool.rb,
lib/errgonomic/core_ext/blank.rb

Overview

The false halves of the conversions above.

Instance Method Summary collapse

Instance Method Details

#blank?true

false is blank:

false.blank? # => true

Returns:

  • (true)


71
72
73
# File 'lib/errgonomic/core_ext/blank.rb', line 71

def blank?
  true
end

#ok_or(err) ⇒ Object

Examples:

false.ok_or(:ohno) # => Err(:ohno)


59
60
61
# File 'lib/errgonomic/core_ext/bool.rb', line 59

def ok_or(err)
  Err(err)
end

#ok_or_else(&block) ⇒ Object

Examples:

false.ok_or_else { :ohno } # => Err(:ohno)


65
66
67
# File 'lib/errgonomic/core_ext/bool.rb', line 65

def ok_or_else(&block)
  Err(block.call)
end

#present?Boolean

:nodoc:

Returns:

  • (Boolean)


75
76
77
# File 'lib/errgonomic/core_ext/blank.rb', line 75

def present? # :nodoc:
  false
end

#then_some(*args, &block) ⇒ Object

The block is never called; arguments are validated all the same, so a misuse fails regardless of which way the flag happens to point.

Examples:

false.then_some(:hello) # => None()
false.then_some { :hello } # => None()
false.then_some # => raise Errgonomic::ArgumentError, "then_some takes either a value or a block"


49
50
51
52
53
54
55
# File 'lib/errgonomic/core_ext/bool.rb', line 49

def then_some(*args, &block)
  unless (args.length == 1 && !block) || (args.empty? && block)
    raise Errgonomic::ArgumentError, 'then_some takes either a value or a block'
  end

  None()
end