Class: Verbalize::Result

Inherits:
Object
  • Object
show all
Defined in:
lib/verbalize/result.rb

Direct Known Subclasses

Failure, Success

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(outcome:, value:) ⇒ Result

Returns a new instance of Result.



3
4
5
6
# File 'lib/verbalize/result.rb', line 3

def initialize(outcome:, value:)
  @outcome = outcome
  @value   = value
end

Instance Attribute Details

#outcomeObject (readonly)

Returns the value of attribute outcome.



8
9
10
# File 'lib/verbalize/result.rb', line 8

def outcome
  @outcome
end

Instance Method Details

#failed?Boolean Also known as: failure?

Returns:

  • (Boolean)


15
16
17
# File 'lib/verbalize/result.rb', line 15

def failed?
  outcome == :error
end

#succeeded?Boolean Also known as: success?

Returns:

  • (Boolean)


10
11
12
# File 'lib/verbalize/result.rb', line 10

def succeeded?
  !failed?
end

#to_aryObject



20
21
22
# File 'lib/verbalize/result.rb', line 20

def to_ary
  [outcome, @value]
end

#valueObject

Raises:

  • (NotImplementedError)


24
25
26
# File 'lib/verbalize/result.rb', line 24

def value
  raise NotImplementedError, 'Subclasses must override Verbalize::Result#value'
end