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

Constructor Details

#initialize(value) ⇒ Success

Returns a new instance of Success.



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

def initialize value
  @value = value.freeze
end

Instance Method Details

#==(other) ⇒ Object



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

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

#===(other) ⇒ Object



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

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

#empty?Boolean

Returns:

  • (Boolean)


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

def empty?() false end

#getObject



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

def get() @value end

#recover(&block) ⇒ Object

Raises:

  • (ArgumentError)


87
88
89
90
# File 'lib/ytry.rb', line 87

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

#to_aryObject



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

def to_ary() [get] end

#to_sObject



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

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