Class: Errgonomic::Result::Err

Inherits:
Any show all
Defined in:
lib/errgonomic/result.rb

Overview

The Err variant.

Defined Under Namespace

Classes: Arbitrary

Constant Summary

Constants inherited from Any

Any::RUST_SPELLINGS

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Any

#<=>, #==, #and, #and_then, #deconstruct, #eql?, #err_and?, #expect!, #hash, #map, #map_err, #method_missing, #ok_and?, #or, #or_else, #pretty_print, #respond_to_missing?, #result?, #tap_err, #tap_ok, #to_json, #to_s, #unwrap!, #unwrap_err!, #unwrap_or, #unwrap_or_else

Constructor Details

#initialize(value = Arbitrary) ⇒ Err

Err may be constructed without a value, if you want.

Examples:

Err(:y).value # => :y
Err().value # => Arbitrary


443
444
445
# File 'lib/errgonomic/result.rb', line 443

def initialize(value = Arbitrary)
  super(value)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Errgonomic::Result::Any

Instance Attribute Details

#valueObject

Returns the value of attribute value.



436
437
438
# File 'lib/errgonomic/result.rb', line 436

def value
  @value
end

Instance Method Details

#err?Boolean

Err is always err

Examples:

Err(:z).err? # => true

Returns:

  • (Boolean)


451
452
453
# File 'lib/errgonomic/result.rb', line 451

def err?
  true
end

#inspectObject

Render like Rust's Debug; a value-less Err renders bare.

Examples:

Err(:nope).inspect # => "Err(:nope)"
Err().inspect # => "Err()"


468
469
470
471
472
# File 'lib/errgonomic/result.rb', line 468

def inspect
  return 'Err()' if value == Arbitrary

  "Err(#{value.inspect})"
end

#ok?Boolean

Err is never ok

Examples:

Err(:A).ok? # => false

Returns:

  • (Boolean)


459
460
461
# File 'lib/errgonomic/result.rb', line 459

def ok?
  false
end