Class: Collins::Some

Inherits:
Option show all
Defined in:
lib/collins/option.rb

Overview

Represents a present value

A number of equality and comparison methods are implemented so that ‘Some` values are compared using the value of `x`.

Instance Method Summary collapse

Methods inherited from Option

#defined?, #exists?, #filter, #filter_not, #flat_map, #foreach, #get_or_else, #map, #or_else

Constructor Details

#initialize(value) ⇒ Some

Returns a new instance of Some.



196
197
198
# File 'lib/collins/option.rb', line 196

def initialize value
  @x = value
end

Instance Method Details

#<=>(other) ⇒ Object



212
213
214
215
# File 'lib/collins/option.rb', line 212

def <=>(other)
  self.class == other.class ?
    (x <=> other.x) : nil
end

#empty?Boolean

Returns:

  • (Boolean)


199
200
201
# File 'lib/collins/option.rb', line 199

def empty?
  false
end

#eql?(other) ⇒ Boolean Also known as: ==

Returns:

  • (Boolean)


205
206
207
# File 'lib/collins/option.rb', line 205

def eql? other
  self.class.equal?(other.class) && x.eql?(other.x)
end

#getObject



202
203
204
# File 'lib/collins/option.rb', line 202

def get
  x
end

#hashObject



209
210
211
# File 'lib/collins/option.rb', line 209

def hash
  x.hash
end