Class: TrueClass
- Defined in:
- lib/errgonomic/core_ext/bool.rb,
lib/errgonomic/core_ext/blank.rb
Overview
Lift booleans into Option and Result, following Rust's bool: then_some,
and ok_or/ok_or_else from nightly. Rust splits the lazy form into then,
but that name is core Ruby (Kernel#then), so then_some takes either a
value or a block. Rust's ok_or returns Result<(), E>; Ruby has no unit
type, so Ok carries true.
Instance Method Summary collapse
-
#blank? ⇒ false
trueis not blank:. - #ok_or(_err) ⇒ Object
- #ok_or_else ⇒ Object
-
#present? ⇒ Boolean
:nodoc:.
- #then_some(*args, &block) ⇒ Object
Instance Method Details
#blank? ⇒ false
true is not blank:
true.blank? # => false
86 87 88 |
# File 'lib/errgonomic/core_ext/blank.rb', line 86 def blank? false end |
#ok_or(_err) ⇒ Object
29 30 31 |
# File 'lib/errgonomic/core_ext/bool.rb', line 29 def ok_or(_err) Ok(true) end |
#ok_or_else ⇒ Object
35 36 37 |
# File 'lib/errgonomic/core_ext/bool.rb', line 35 def ok_or_else Ok(true) end |
#present? ⇒ Boolean
:nodoc:
90 91 92 |
# File 'lib/errgonomic/core_ext/blank.rb', line 90 def present? # :nodoc: true end |
#then_some(*args, &block) ⇒ Object
17 18 19 20 21 22 23 24 25 |
# File 'lib/errgonomic/core_ext/bool.rb', line 17 def then_some(*args, &block) if args.length == 1 && !block Some(args[0]) elsif args.empty? && block Some(block.call) else raise Errgonomic::ArgumentError, 'then_some takes either a value or a block' end end |