Class: SuccessResult
- Includes:
- Singleton
- Defined in:
- lib/success_result.rb
Overview
SuccessResult represents a successful outcome when no specific result value is produced.
This class follows the Null Object pattern for successful cases, ensuring a consistent interface with methods such as #success? and #failure?. It is implemented as a singleton, meaning there is only one instance of SuccessResult available.
Example:
result = SomeService.call
if result.success?
# proceed knowing the operation succeeded
else
# handle failure
end
Instance Method Summary collapse
-
#failure? ⇒ Boolean
Indicates that the result is not a failure.
-
#message ⇒ String
Provides a default message for the successful result.
-
#success? ⇒ Boolean
Indicates that the result is a success.
-
#to_s ⇒ String
Returns a string representation of this SuccessResult.
Instance Method Details
#failure? ⇒ Boolean
Indicates that the result is not a failure.
40 41 42 |
# File 'lib/success_result.rb', line 40 def failure? false end |
#message ⇒ String
Provides a default message for the successful result.
48 49 50 |
# File 'lib/success_result.rb', line 48 def 'Success' end |
#success? ⇒ Boolean
Indicates that the result is a success.
32 33 34 |
# File 'lib/success_result.rb', line 32 def success? true end |
#to_s ⇒ String
Returns a string representation of this SuccessResult.
56 57 58 |
# File 'lib/success_result.rb', line 56 def to_s 'SuccessResult' end |