Class: Ytry::Success

Inherits:
Object
  • Object
show all
Includes:
Try
Defined in:
lib/ytry.rb

Instance Method Summary collapse

Methods included from Try

ary_to_type, #each, #flat_map, #flatten, #get_or_else, #grep, #inspect, #map, #on_failure, #or_else, #reject, #select, zip, #zip, #|

Constructor Details

#initialize(value) ⇒ Success

Returns a new instance of Success.



101
102
103
# File 'lib/ytry.rb', line 101

def initialize value
  @value = value.freeze
end

Instance Method Details

#==(other) ⇒ Object



108
109
110
# File 'lib/ytry.rb', line 108

def == other
  other.is_a?(Success) && self.get == other.get
end

#===(other) ⇒ Object



111
112
113
# File 'lib/ytry.rb', line 111

def === other
  other.is_a?(Success) && self.get === other.get
end

#empty?Boolean

Returns:

  • (Boolean)


105
# File 'lib/ytry.rb', line 105

def empty?() false end

#getObject



104
# File 'lib/ytry.rb', line 104

def get() @value end

#recover(&block) ⇒ Object

Raises:

  • (ArgumentError)


114
115
116
117
# File 'lib/ytry.rb', line 114

def recover &block
  raise ArgumentError, 'missing block' unless block_given?
  self
end

#recover_with(&block) ⇒ Object

Raises:

  • (ArgumentError)


118
119
120
121
# File 'lib/ytry.rb', line 118

def recover_with &block
  raise ArgumentError, 'missing block' unless block_given?
  self
end

#to_aryObject



107
# File 'lib/ytry.rb', line 107

def to_ary() [get] end

#to_sObject



106
# File 'lib/ytry.rb', line 106

def to_s() "Success(#{get})" end