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, #or_else, #zip, #|

Constructor Details

#initialize(value) ⇒ Success

Returns a new instance of Success.



71
72
73
# File 'lib/ytry.rb', line 71

def initialize value
  @value = value.freeze
end

Instance Method Details

#==(other) ⇒ Object



78
79
80
# File 'lib/ytry.rb', line 78

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

#===(other) ⇒ Object



81
82
83
# File 'lib/ytry.rb', line 81

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

#empty?Boolean

Returns:

  • (Boolean)


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

def empty?() false end

#getObject



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

def get() @value end

#recover(&block) ⇒ Object

Raises:

  • (ArgumentError)


84
85
86
87
# File 'lib/ytry.rb', line 84

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

#to_aryObject



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

def to_ary() [get] end

#to_sObject



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

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