Class: Mona::Result::Action::Ephemeral
- Inherits:
-
Object
- Object
- Mona::Result::Action::Ephemeral
- Includes:
- Mona::Result::Action
- Defined in:
- lib/mona/result/action.rb
Overview
You can create an Ephemeral Action as follows:
Example:
compute = Mona::Result::Action::Ephemeral.new do |x, y|
set :numerator, x
puts "set numerator: #{numerator}"
set :denominator, y.zero? ? Result.failure(y, :zero) : y
puts "set denominator: #{denominator}"
set :answer, numerator / denominator
puts "answer: #{answer}"
end
> compute.call(10,2)
set numerator: 10
set denominator: 2
answer: 5
=> #<Result success: {:numerator=>10, :denominator=>2, :answer=>5}>
> compute.call(10,0)
set numerator: 10
=> #<Result failure: {:numerator=>10, :denominator=>0}, error: {:error=>:zero, :on=>:denominator}>
Mona::Result.action is a shortcut for this
Instance Method Summary collapse
-
#initialize(&perform) ⇒ Ephemeral
constructor
A new instance of Ephemeral.
- #perform(*args, **kwargs) ⇒ Object
Methods included from Mona::Result::Action
Constructor Details
#initialize(&perform) ⇒ Ephemeral
Returns a new instance of Ephemeral.
57 58 59 |
# File 'lib/mona/result/action.rb', line 57 def initialize(&perform) @perform = perform end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Mona::Result::Action
Instance Method Details
#perform(*args, **kwargs) ⇒ Object
61 |
# File 'lib/mona/result/action.rb', line 61 def perform(*args, **kwargs) = instance_exec(*args, **kwargs, &@perform) |