Class: Monads::Optional
- Inherits:
-
Object
- Object
- Monads::Optional
- Includes:
- Monad
- Defined in:
- lib/monads/optional.rb
Instance Attribute Summary collapse
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Class Method Summary collapse
Instance Method Summary collapse
- #and_then(&block) ⇒ Object
-
#initialize(value) ⇒ Optional
constructor
A new instance of Optional.
- #respond_to_missing?(method_name, include_private = false) ⇒ Boolean
Methods included from Monad
Constructor Details
#initialize(value) ⇒ Optional
Returns a new instance of Optional.
9 10 11 |
# File 'lib/monads/optional.rb', line 9 def initialize(value) @value = value end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Monads::Monad
Instance Attribute Details
#value ⇒ Object (readonly)
Returns the value of attribute value.
7 8 9 |
# File 'lib/monads/optional.rb', line 7 def value @value end |
Class Method Details
Instance Method Details
#and_then(&block) ⇒ Object
13 14 15 16 17 18 19 20 21 |
# File 'lib/monads/optional.rb', line 13 def and_then(&block) block = ensure_monadic_result(&block) if value.nil? self else block.call(value) end end |
#respond_to_missing?(method_name, include_private = false) ⇒ Boolean
23 24 25 |
# File 'lib/monads/optional.rb', line 23 def respond_to_missing?(method_name, include_private = false) super || value.nil? || value.respond_to?(method_name, include_private) end |