Module: Either
Overview
Chain various method calls
Defined Under Namespace
Classes: Chain
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object
- #bind(proc = nil, &block) ⇒ Object (also: #>=, #+)
- #failure? ⇒ Boolean
- #fetch(default = @value) ⇒ Object (also: #_)
- #success? ⇒ Boolean
- #to_s ⇒ Object
Class Method Details
Instance Method Details
#==(other) ⇒ Object
43 44 45 46 |
# File 'lib/monadic/either.rb', line 43 def ==(other) return false unless self.class === other return other.fetch == @value end |
#bind(proc = nil, &block) ⇒ Object Also known as: >=, +
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/monadic/either.rb', line 21 def bind(proc=nil, &block) return self if failure? begin result = if proc && proc.arity == 0 then proc.call else (proc || block).call(@value) end result ||= Failure(nil) result = Either(result) unless result.is_a? Either result rescue Exception => ex Failure(ex) end end |
#fetch(default = @value) ⇒ Object Also known as: _
15 16 17 18 |
# File 'lib/monadic/either.rb', line 15 def fetch(default=@value) return default if failure? return @value end |
#to_s ⇒ Object
39 40 41 |
# File 'lib/monadic/either.rb', line 39 def to_s "#{self.class.name}(#{@value.nil? ? 'nil' : @value.to_s})" end |