Class: Unparser::Either

Inherits:
Object
  • Object
show all
Includes:
Adamantium, RequireBlock
Defined in:
lib/unparser/either.rb

Overview

RequireBLock

Direct Known Subclasses

Left, Right

Defined Under Namespace

Classes: Left, Right

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.wrap_error(*exceptions) ⇒ Either<Exception, Object>

Execute block and wrap error in left

Parameters:

  • exception (Class<Exception>)

Returns:



33
34
35
36
37
# File 'lib/unparser/either.rb', line 33

def self.wrap_error(*exceptions)
  Right.new(yield)
rescue *exceptions => error
  Left.new(error)
end

Instance Method Details

#left?Boolean

Test for left constructor

Returns:

  • (Boolean)


42
43
44
# File 'lib/unparser/either.rb', line 42

def left?
  instance_of?(Left)
end

#right?Boolean

Test for right constructor

Returns:

  • (Boolean)


49
50
51
# File 'lib/unparser/either.rb', line 49

def right?
  instance_of?(Right)
end